Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22004

GCC inline assembly with stack operation

$
0
0

I am in need of such a inline assembly code:

  • I have a pair(so, it is balanced) of push/pop operation inside the assembly
  • I also have a variable in memory (so, not register) as input

like this:

__asm__ __volatile__ ("push %%eax\n\t"
        // ... some operations that use ECX as a temporary
        "mov %0, %%ecx\n\t"
        // ... some other operation
        "pop %%eax"
: : "m"(foo));
// foo is my local variable, that is to say, on stack

When disassembling the compiled code, the compiler give the memory address like 0xc(%esp), it is relative to esp, hence, this fragment of code will not works correctly since I have a push operation before mov. Therefore, how can I tell the compile I do not like the foo relative to esp, but any thing like -8(%ebp) relative to ebp.

P.S. You may suggest that I can put eax inside the Clobbers, but it is just a sample code. I don't like to show the full reason why I don't accept this solution.


Viewing all articles
Browse latest Browse all 22004

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>