title: Assembly - Swap function - Why it will not work?
body: <p>I need to create a function that swaps the value of &amp;x with the value of &amp;y (meaning swap *(&amp;y) and *(&amp;x).</p>
  
  <pre><code>Swap:
  
      push EBP
      mov EBP,ESP
      mov EBX, [EBP+12] ; ebx = *x
      mov EAX, DWORD [EBX] ;eax = ebx = *x
      mov DWORD [EBP-4], EAX ; [ebp-4] = eax =*x
      mov EDX, [EBP+8] ; edx = *y
      mov EAX, DWORD [EDX] ; eax = *edx = *y
      mov DWORD [EBX], EAX ; ebx = eax = *y
      mov EAX, DWORD [EBP-4] ; eax = *x
      mov DWORD [EDX], EAX ; edx = *x
      pop EBP ; ebx = *y and edx = *x
      ret
  </code></pre>
  
  <p>I call it like this:</p>
  
  <pre><code>    // call Swap
      push x
      push y
      call swap
  </code></pre>
  
  <p>I don't understand why it's not working. I added comments that explain my understanding of it. What's wrong with my implementation? How can I fix it?</p>