MORE INFORMATION
Case 1
In the following code fragment, both mov instructions move dataitem into
the ax register.
.DATA
dataitem DW 0
.CODE
mov ax, dataitem
mov ax, [dataitem]
The results are the same because the assembler determines the addressing
mode based on the way that dataitem is declared. In both cases,
dataitem is a label, so the assembler will access the data located at the
label.
If you really want to access dataitem as a constant value, use the
following syntax:
.CODE
mov ax, OFFSET dataitem
In this case, OFFSET tells the assembler to treat dataitem as a constant
value rather than as a data item that is located at a memory location.
Case 2
In the following code fragment, both mov instructions move 0 into the
ax register.
datavalue EQU 0
.CODE
mov ax, datavalue
mov ax, [datavalue]
Again, the result is the same, because the assembler determines the
addressing mode based on the way datavalue is declared. In both cases,
datavalue is an equate, so the assembler will treat datavalue as a
constant value.
If you want to access datavalue as a data item located at a memory
location, use the following syntax:
.CODE
mov ax, ds:datavalue
In this case, the segment override tells the assembler to treat datavalue
as a data item that is located at ds:datavalue, rather than treating
datavalue as a constant value.
Case 3
On the other hand, with the following code fragment, the mov instructions
have different results.
.CODE
mov ax, bx
mov ax, [bx]
In the first case, we are moving what is in bx into ax. In the second
case, we are using bx as an offset and moving what is at that offset into
ax. The assembler determines what to do based on the brackets or lack of
brackets around the register. This is the only case where the brackets
have this effect.