As some of the other answers say, the offset
keyword refers to the offset from the segment in which it is defined. Note, however, that segments may overlap and the offset in one segment may be different in another segment. For instance, suppose you have the following segment in real mode
data SEGMENT USE16 ;# at 02000h
org 0100h
foo db 0
org 01100h
bar db 0
data ENDS
And look at the following code:
mov ax, 0200h
mov ds, ax
mov bx, offset foo ; bx = 0100h
mov byte ptr [bx], 10 ; foo = 10
mov ax, 0300h
mov ds, ax
mov bx, offset foo; bx = 0100h
mov byte ptr [bx], 10 ; bar = 10
The assembler sees that foo
is at offset 0100h
from the base of data SEGMENT
, so wherever it sees offset foo
it will put the value 0100h
, regardless of the value of DS
at the time.
In the second example DS
is 0300h
, so the base of the segment pointed to by DS
is 03000h
. This means that ds:[offset foo]
points to the address 03000h + 0100h
which is the same as 02000h + 01100h
, which points to bar
.