title: How to index an array in a function in nasm assembly?
body: <p>As per the question, how do I index arrays in nasm assembly that are inside a function? I always get the error invalid effective address whenever I compile my code, and based on the searches I have done, it has something to do with the registers I use when I index. Even then, I am still not sure what registers to use given the different architectures of assembly.</p>
  <pre><code>get_largest:
  
  mov rcx, 5
  mov bl, 0
  mov al, 0
  
  neg_loop:
  cmp rcx, 0
  je check_neg
  cmp dword[rdi+al*2], 0
  jl incbl
  inc al
  jmp neg_loop
  incbl:
  inc al
  inc bl
  jmp neg_loop
  
  check_neg:
  cmp bl, 5
  jl check_largest
  mov rsi, 1
  mov rdx, -1
  jmp return
  
  check_largest:
  mov rsi, 0
  mov rcx, 5
  mov al, 0
  mov bl, 0
  
  large:
  cmp rcx, 0
  je greatest
  cmp dword[rdi+al*2], bl
  jg larger
  inc al
  jmp large
  
  larger:
  mov bl, dword[rdi+al*2]
  inc al
  jmp large
  
  greatest:
  mov rdi, bl
  
  return:
      ret 
  </code></pre>
  <p>Here is my function and the compile error occurs at <code>cmp dword[rdi+al*2], 0</code></p>