Direct-Offset Operands


To create a direct-offset operand, add a displacement to the name of a variable.

An expression such as myString+1 produces what is called an effective address by adding a constant to the variable's offset.

 .data
 myString  BYTE  "ABCDEFG", 0
 .code
 mov  al, myString          ; AL = 'A'
 mov  al, [myString+1]      ; AL = 'B'
 mov  al, [myString+2]      ; AL = 'C'

The brackets (dereferencing) are not required, i.e., the following two commands are equal:
     mov  al, [myString+1]
     mov  al, myString+1

Range Checking
MASM has no built-in range checking for effective addresses. The code on the right does not put any letter in the string to the AL register.

 .data
 myString  BYTE  "ABCDEFG", 0
 .code
 mov  al, myString+20       ; AL = ?

 al = [X+1]  ax = [X+1]  ax = [X+1]
 .data
 X  WORD  10h, 20h, 30h
 .code
 mov   eax, 0
 mov   al, X+1
 call  WriteHex
 .data
 X  WORD  10h, 20h, 30h
 .code
 mov   eax, 0
 mov   ax, X+1
 call  WriteHex
 .data
 X   WORD  10h, 20h, 30h
 .code
 mov   eax, 0
 mov   ebx, offset X
 mov   ax, [ebx+1]
 call  WriteHex
 Output  Output  Output