Memory Addressing (Cont.)


Indirect Memory Addressing
Indirect memory addressing uses a register as a pointer and manipulates the register's value. A register holding an address is called an indirect operand. An indirect operand can be any 32-bit general-purpose register surrounded by brackets. It can be used to point to different array elements.

 mov al, [esi]  inc [esi]  inc BYTE PTR [esi]
 
 
 .data
 
 
 X  BYTE  10
 
 
 .code
 
 
 mov    esi, OFFSET X
 
 
 mov    al, [esi]
 
 
 add    al, 1
 
 
 mov    X, al
 
 
 movzx  eax, X
 
 
 call   WriteInt
 
 
 .data
 
 
 X  BYTE  10
 
 
 .code
 
 
 mov    esi, OFFSET X
 
 
 inc    [esi]
 
 
 movzx  eax, X
 
 
 call   WriteInt
 
 
 .data
 
 
 X  BYTE  10
 
 
 .code
 
 
 mov    esi, OFFSET X
 
 
 inc    BYTE PTR [esi]
 
 
 movzx  eax, X
 
 
 call   WriteInt
 Output  Output  Output
   



   



   




If the two operands of an instruction are a register and the contents of an address, the size is determined by the register.

 Adding up Array Elements   Adding up Elements of a Column 
 
 
 .data
 
 
     array  WORD  10, 20, 30, 40
 
 
 .code
 
 
     mov   esi, OFFSET array
 
 
     mov   eax, 0
 
 
     mov   ecx, LENGTHOF array
 
 
 L1: add   ax, [esi]
 
 
     add   esi, 2
 
 
     loop  L1
 
 
     call  WriteInt
 
 
 .data
 
 
     tbl   WORD  10, 20, 30,
 
 
                 40, 50, 60,
 
 
                 70, 80, 90
 
 
 .code
 
 
     mov   esi, OFFSET tbl
 
 
     mov   eax, 0
 
 
     mov   ecx, 3
 
 
 L1: add   ax, [esi]
 
 
     add   esi, 6
 
 
     loop  L1
 
 
     call  WriteInt
 Output   Output 

   


   



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