OFFSET operator:
The offset operator returns the number of bytes between the label
and the beginning of its segment.
Since it produces a 16-bit immediate value, the destination must
be a 16-bit operand.
After executing the following instruction, the BX register contains the
address of the variable count. BX may thus be used as a pointer to the count
variable.
Example 1: The OFFSET operator |
mov bx, offset count ; Let BX point to count
|
Example 2: The OFFSET operator |
.data
bList db 10h, 20h, 30h, 40h
wList dw 1000h, 2000h, 3000h
.code
mov di, offset bList ; DI = 0000
mov bx, offset bList+1 ; BX = 0001
mov si, offset wList+2 ; SI = 0006
.....
|
The SEG operator:
The SEG operator returns the segment part of a label or variable’s address.
It is usually used when a variable is in a segment other than the current
data segment, such as an external variable.
Example 1: The SEG operator |
MOV AX, SEG My_msg ;Load AX with the data segment number
;where the variable My_msg is declared.
MOV DS, AX ;Let DS point to that data segment
|
In the followig example, the variable array is an external variable.
The DS register is made to point to the segment that contains the
array variable for the temporary duration of the execution of the
code that operates on the variable array.
Example 2: The SEG operator |
push ds ; save DS
mov ax, seg array ; set DS to segment of array
mov ds, ax
mov bx, offset array ; get the array offset
... ; perform the array processing
; at this level.
pop ds ; restore DS
|
|