title: Addressing Modes in Assembly Language (IA-32 NASM)
body: <p>As the web-resources on this is sparse, I will, for the benefit of future searches, begin by listing the address modes for IA-32 Assembly Language (NASM) and then follow up with a quick question.</p>
  
  <ol>
  <li>Register addressing
  <ul>
  <li>mov eax, ebx: Copies what is in ebx into eax</li>
  <li>mov esi, var: Copies address of var (say 0x0040120e) into esi</li>
  </ul></li>
  <li>Immediate addressing (second operand is an immediate constant)
  <ul>
  <li>mov bx, 20: 16-bit register bx gets the actual value 20</li>
  </ul></li>
  <li>Direct memory addressing (directly loads from memory through a specified address)
  <ul>
  <li>mov ax, [1000h]: loads a 2-byte object from the byte at address 4096 (0x1000 in hexadecimal) into a 16-bit register called 'ax'</li>
  <li>mov [1000h], ax: memory at address 1000h gets the value of ax</li>
  </ul></li>
  <li>Direct offset addressing (same as 3, just using arithmetics to modify address)
  <ul>
  <li>mov al, [byte_tbl+2]</li>
  </ul></li>
  <li>Register indirect (accessing memory by using addresses stored in registers)
  <ul>
  <li>mov ax, [di]: copies value at memory address specified by di, into ax</li>
  <li>mov dword [eax], var1: copies value in var1 into the memory slot specified by eax</li>
  </ul></li>
  </ol>
  
  <p>Please note that the above is for NASM. For MASM/TASM you'd use "mov esi, OFFSET foo" to get the address, while "mov esi, foo" and "mov esi, [foo]" both would get the value (creds to @Michael).</p>
  
  <p>So, onto my question. It is in in relation to an example at the bottom of page 29 of the following tutorial: <a href="http://www.tutorialspoint.com/assembly_programming/assembly_tutorial.pdf">http://www.tutorialspoint.com/assembly_programming/assembly_tutorial.pdf</a></p>
  
  <p>It basically lists the below code as an example of indirect memory addressing.</p>
  
  <pre><code>MY_TABLE TIMES 10 DW 0 ; Allocates 10 words (2 bytes) each initialized to 0 
  MOV EBX, [MY_TABLE] ; Effective Address of MY_TABLE in EBX 
  MOV [EBX], 110 ; MY_TABLE[0] = 110 
  ADD EBX, 2 ; EBX = EBX +2 
  MOV [EBX], 123 ; MY_TABLE[1] = 123 
  </code></pre>
  
  <p><strong>My questions:</strong></p>
  
  <ol>
  <li>Should not "MOV EBX, [MY_TABLE]" in fact be "MOV EBX, MY_TABLE", as we want to put the address of the table in EBX, not the value itself?</li>
  <li>Surely it is MY_TABLE[2] that is equal to 123 at the end, not MY_TABLE[1]?</li>
  </ol>