Direct-Offset Operands


To create a direct-offset operand, add a displacement to the name of a variable. An expression such as produces what is called an effective address by adding a constant to the variable’s offset.
 INCLUDE Irvine32.inc
 .data
  myString  BYTE  "ABCDEFG", 0
 .code
 main PROC
  mov  al, myString          ; AL = 'A'
  mov  al, [myString+1]      ; AL = 'B'
  mov  al, [myString+2]      ; AL = 'C'
  exit
 main ENDP
 END main

The brackets (dereferencing) are not required, i.e., the 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 register:
 INCLUDE Irvine32.inc
 .data
  myString  BYTE  "ABCDEFG", 0
 .code
 main PROC
  mov  al, myString+20     ; AL = ?
  exit
 main ENDP
 END main

al = [X+1] ax = [X+1] ax = [X+1]
 INCLUDE Irvine32.inc
 .data
  X  WORD  10h, 20h, 30h
 .code
 main PROC
  mov   eax, 0
  mov   al, X+1
  call  WriteHex
  exit
 main ENDP
 END main
 INCLUDE Irvine32.inc
 .data
  X  WORD  10h, 20h, 30h
 .code
 main PROC
  mov   eax, 0
  mov   ax, X+1
  call  WriteHex
  exit
 main ENDP
 END main
 INCLUDE Irvine32.inc
 .data
  X   WORD  10h, 20h, 30h
 .code
 main PROC
  mov   eax, 0
  mov   ebx, offset X
  mov   ax, [ebx+1]
  call  WriteHex
  exit
 main ENDP
 END main
Output Output Output

 

 

 

 

 

 






      “I’m not arguing, I’m just explaining why I’m right.”    
      ― Unknown