Memory Addressing (Cont.)


Base Displacement Addressing (Indexed Operands)
An indexed operand adds a constant to a register to generate an effective address.

If the two operands of an instruction are the contents of an address and a constant, the size of the contents needs to be specified.

WORD PTR [ebx+4] WORD PTR 4[ebx] X[ebx]
 INCLUDE Irvine32.inc
 .data
  X WORD 10, 20, 30, 40
 .code
 main PROC
  mov   ebx, OFFSET X
  mov WORD PTR [ebx+4],\
     60
  movzx eax, X+4
  call  WriteInt
  exit
 main ENDP
 END main
 INCLUDE Irvine32.inc
 .data
  X WORD 10, 20, 30, 40
 .code
 main PROC
  mov   ebx, OFFSET X
  mov WORD PTR 4[ebx],\
     60
  movzx eax, X+4
  call  WriteInt
  exit
 main ENDP
 END main
 INCLUDE Irvine32.inc
 .data  
  X WORD 10, 20, 30, 40
 .code
  main PROC
  mov   ebx, 4
  mov   X[ebx], 60
  movzx eax, X+4
  call  WriteInt
  exit
 main ENDP
 END main
Output Output Output

 

 

 

 

 

 

Adding up Array Elements by Using
Indirect Operands Indexed Operands
 INCLUDE Irvine32.inc
 .data
   X  WORD  10, 20, 30, 40
 .code
 main PROC
     mov   eax, 0
     mov   ecx, LENGTHOF X
     mov   esi, OFFSET X
 L1: add   ax, [esi]
     add   esi, 2
     loop  L1
     call  WriteInt
     exit
 main ENDP
 END main
 INCLUDE Irvine32.inc
 .data
   X  WORD  10, 20, 30, 40
 .code
 main PROC
   mov   eax, 0
   mov   esi, 0
   add   ax, X[esi*TYPE X]
   inc   esi
   add   ax, X[esi*TYPE X]
   inc   esi
   add   ax, X[esi*TYPE X]
   inc   esi
   add   ax, X[esi*TYPE X]
   call  WriteInt
  exit
 main ENDP
 END main
Output Output

 

 

 

 






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