Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

Watcom ASM + C puzzle, variable has conflicting addresses (Developers)

posted by samwdpckr, 02.01.2026, 08:50

mov bx, offset symbol_name loads the BX register with the address of the symbol, which is an immediate number.

mov bh, byte ptr [symbol_name] uses the symbol as a pointer and copies the contents of that memory address into the BH register.

mov bh, byte ptr symbol_name copies the value from the symbol's own memory address into the BH register.

When you are writing assembly, the symbol also probably resides in the code segment, so what you want to do is loading a 8-bit register with the value of that symbol, what you probably want to do is

mov bh, byte ptr cs:symbol_name

In any case you should always make sure that the segment registers point into correct paragraphs. But sometimes it's just more efficient to do a segment override instead of loading the segment registers with new values.

In large memory model, if the symbol is in the DGROUP segment, you first have to load a segment register (either DS or ES, or GS/FS if you use a 386+) with the paragraph address where DGROUP starts before you can access the symbol. Be sure to also save and restore the value of the segment register before modifying it.

Accessing data where DS points to does not need a segment override, but other segment registers need it. In other words, DS is the default segment.

 

Complete thread:

Back to the forum
Board view  Mix view
23153 Postings in 2179 Threads, 404 registered users (0 online)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum