title: Indexed addressing mode
body: <p>I have been experimenting with different addressing modes and doing research on the subject; in my attempt to use indexed addressing mode, I borrowed pieces of code from different examples on SO.  In the example below:</p>
  
  <pre><code>outerLoop:
  cmp edi, 50                  ;each element is 2 bytes (2 ascii characters)
  ja  endloop                  ;we need 50 because it's 5 elements per row
  mov esi, 0                   ;and 5 rows
  innerLoop:
  cmp esi, 5                   ;Compare esi(inner loop index) to 5
  jae innerEnd                 ;jump if it reached the end of the row
  mov ax, matrix[edi + esi*2]
  cmp ax, cx
  jg  biggerThan
  mov cx, ax
  </code></pre>
  
  <p>The author is using a nested loop to parse through a 2-d array, and find the smallest number.
  What I am really interested in, is(case 1):</p>
  
  <pre><code>mov ax, matrix[edi + esi*2]
  </code></pre>
  
  <p>As this part seems to cause a problem when compiling the code and it gives the error:
  "comma, colon or end of line expected"
  If I however change the code to(case 2):</p>
  
  <pre><code>[matrix + edi + esi*2]
  </code></pre>
  
  <p>Everything seems to be working fine.</p>
  
  <p>Which one is the correct indexed addressing mode?
  My intuition says that since "matrix" is the array, it should reside outside of the left bracket but that does not seem to be the case in practice.
  I would appreciate if someone could explain the difference between case 1 and case 2.</p>