title: GCC inline - push address, not its value to stack
body: <p>I'm experimenting with GCC's inline assembler (I use MinGW, my OS is Win7).
  Right now I'm only getting some basic C stdlib functions to work. I'm generally familiar with the Intel syntax, but new to AT&amp;T.</p>
  
  <p>The following code works nice:</p>
  
  <pre><code>char localmsg[] = "my local message";
  asm("leal %0, %%eax" : "=m" (localmsg));
  asm("push %eax");
  asm("call %0" : : "m" (puts));
  asm("add $4,%esp");
  </code></pre>
  
  <p>That LEA seems redundant, however, as I can just push the value straight onto the stack. Well, due to what I believe is an AT&amp;T peculiarity, doing this:</p>
  
  <pre><code>asm("push %0" : "=m" (localmsg));
  </code></pre>
  
  <p>will generate the following assembly code in the final executable:</p>
  
  <pre><code>PUSH DWORD PTR SS:[ESP+1F]
  </code></pre>
  
  <p>So instead of pushing the address to my string, its contents were pushed because the "pointer" was "dereferenced", in C terms. This obviously leads to a crash.</p>
  
  <p>I believe this is just GAS's normal behavior, but I was unable to find any information on how to overcome this. I'd appreciate any help.</p>
  
  <p>P.S. I know this is a trivial question to those who are experienced in the matter. I expect to be downvoted, but I've just spent 45 minutes looking for a solution and found nothing.</p>
  
  <p>P.P.S. I realize the proper way to do this would be to call <code>puts( )</code> in the C code. This is for purely educational/experimental reasons.</p>