Slide 8.8: Memory addressing (cont.)
Slide 8.10: Pointers
Home

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]
 .data
 X WORD 10, 20, 30, 40
 .code
 mov   ebx, OFFSET X
 mov WORD PTR [ebx+4],\
     60
 movzx eax, X+4
 call  WriteInt
 .data
 X WORD 10, 20, 30, 40
 .code
 mov   ebx, OFFSET X
 mov WORD PTR 4[ebx],\
     60
 movzx eax, X+4
 call  WriteInt
 .data
 X WORD 10, 20, 30, 40
 .code
 mov   ebx, 4
 mov   X[ebx], 60
 movzx eax, X+4
 call  WriteInt
 Output   Output   Output 
   



   



   




 Adding up Array Elements by Using 
 Indirect Operands   Indexed Operands 
 .data
     X  WORD  10, 20, 30, 40
 .code
     mov   eax, 0
     mov   ecx, LENGTHOF X
     mov   esi, OFFSET X
 L1: add   ax, [esi]
     add   esi, 2
     loop  L1
     call  WriteInt
 .data
 X  WORD  10, 20, 30, 40
 .code
 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
 Output   Output