title: NASM Reverse an integer array
body: <p>Conceptually, I'm trying to push the values onto the stack and pop them off in "opposite" order.  In practice, I think I'm doing that but I'm not sure.  The array I'm passing is defined in the <code>section .data</code> as <code>array: dd 1, 2, 3, 4, 5, 6</code> and the size is being passed as an int value (3 = 3 elements).  When I run the application, it links and assembles but the array is not reversed.  </p>
  
  <pre><code>push dword array
  push dword [arrayLen]
  call reverse
  add esp, 8
  
  ; other stuff
  
  reverse:
      push ebp                    ; setup stack
      mov ebp,esp 
      sub esp,0x40                ; 64 bytes of local stack space 
  
      ; put parameters into registers
      mov ebx, [ebp+12]           ; array
      mov edx, [ebp+8]            ; len
  
      ; set up loop
      mov ecx, 0
  
      ; push all the values onto the stack
      .loopPush:
          mov eax, 4
          mul ecx
          push dword [ebx]
          add ecx, 1
          cmp ecx, edx
              jl .loopPush
      mov ecx, 0
  
      ; pop all the values from the stack
      .loopPop:
          mov eax, 4
          mul edx
          pop dword [ebx+edx]
          add ecx, 1
          cmp ecx, edx
              jl .loopPop
  
      ; print the array
      push dword [ebp+12]
      push dword [ebp+8]
      call printArray
      add esp, 8
  
      .end:
          mov esp,ebp             ; undo "sub esp,0x40" above 
          pop ebp
          mov eax, ebx                ; return the reversed array
          ret 
  </code></pre>
  
  <p>The print function accurately prints whatever I give it so I'm about 90% certain it's not an issue when printing.  Thanks in advance!</p>