title: Passing parameters by reference from C++ to x86 MASM
body: <p>I'm trying to pass parameters by reference from C++ to a function written in assembly, but I can't seem to actually change the value within the assembly function. What am I doing wrong here?</p>
  <pre><code>void __declspec(naked) asmChange(int&amp;){
    __asm{
      mov   [esp+4], 5
      ret
    }
  }
  
  int main (){
    int a = 12;
    cout &lt;&lt; &quot;Before: &quot; &lt;&lt; a &lt;&lt; endl;
    asmChange(a);
    cout &lt;&lt; &quot;After: &quot; &lt;&lt; a &lt;&lt; endl;
    return 0;
  }
  </code></pre>
  <p>In the program above I'm simply trying to change the value of a variable. I don't really understand what I'm doing wrong here and can't seem to find any answers to my issue anywhere else online.</p>