title: Exhange two variables passed by reference won't cooperate
body: <p>Please consider the below MASM assembly code snippet.  As is, it will jmp to skip2 and works just fine.  Comment out the jmp skip2 line and the first half executes - actually it doesn't. Instead, in VS2015 debug mode, I get an access violation error.  I've attached an excel diagram of my interpretation of the stack activation record. Under (1) is esp and the offsets - this works fine if you jmp to skip2.</p>
  
  <p>Under (2) is ebp and its offsets (I think), which would say [ebp+40] and [ebp+44] should work. It doesn't, nor does my other naïve thought (3) that maybe with pushad, that is the correct place to start with ebp.  Green shows the result of the stack following the pushad instruction.  Yellow shows the targets, namely @I and @k, that obviously need to be dereferenced.</p>
  
  <p>Where am I going wrong?</p>
  
  <pre><code>Exchange    PROC
      pushad
      jmp skip2    ; comment this jmp instruction out and works fine. 
      push ebp
      mov ebp, esp
      mov eax, [ebp+44]       ; eax gets @k
      mov ecx, [eax]          ; ecx gets k.
      mov ebx, [ebp+40]       ; ebx gets @i.
      mov edx, [ebx]          ; edx gets i.
      mov [eax], edx          ; k = i.
      mov [ebx], ecx          ; i = k.
      pop     ebp        ; EDITED:  THIS IS THE FIX
      jmp ende
  skip2:
      mov eax, [esp+40]       ; eax gets @k
      mov ecx, [eax]          ; ecx gets k.
      mov ebx, [esp+36]       ; ebx gets @i.
      mov edx, [ebx]          ; edx gets i.
      mov [eax], edx          ; k = i.
      mov [ebx], ecx          ; i = k.
  ende:
      popad
      ret 8
  Exchange    ENDP
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/I3N26.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I3N26.jpg" alt="enter image description here"></a></p>