title: Contextual differences in inline assembly code
body: <p>Along the lines with the first answer <a href="https://stackoverflow.com/questions/7776451/running-shellcode-vs2010">here</a> I tried to encapsulate some assembly code in a C++ function.</p>
  
  <p>When I put this code in a function (inline or not) and pass the shellcode as an argument to the function it gives me an access violation 0xC0000005 at the <code>call</code> instruction, with or without DEP enabled. However, when I define the shellcode inside the function just before VirtualProtect, it works fine.</p>
  
  <p>Current function code:</p>
  
  <pre><code>inline void ExecuteShellcode(char shellcode[])
  {
      /*char shellcode[] = \
      "shellcode"; // If I use this local variable instead of the argument it works tho
      */
      DWORD tempstore;
      if (VirtualProtect(shellcode, sizeof(shellcode), PAGE_EXECUTE_READWRITE, &amp;tempstore))
      {
          __asm lea eax, shellcode;
          __asm call eax; Access violation 0xC0000005
      }
  }
  </code></pre>
  
  <p>Why does <code>__asm call</code> not work with non-local variables in this instance?</p>