Reputation: 1371
I'm not sure what this inline assembly does:
asm ("mov %%esp, %0" : "=g" (esp));
especially the : "=g" (esp)
part.
Upvotes: 8
Views: 3107
Reputation: 71525
If you want the gory details, read the GCC documentation on Extended Asm.
The short answer is that this moves the x86 stack pointer (%esp register) into the C variable named "esp". The "=g" tells the compiler what sorts of operands it can substitute for the %0
in the assembly code. (In this case, it is a "general operand", which means pretty much any register or memory reference is allowed.)
Upvotes: 9
Reputation: 39905
"=g" (esp)
defines an output for the inline assembly. The g
tells the compiler that it can use any general register, or memory, to store the result. The (esp)
means that the result will be stored in the c variable named esp
. mov %%esp, %0
is the assembly command, which simply moves the stack pointer into the 0th operand (the output). Therefore, this assembly simply stores the stack pointer in the variable named esp
.
Upvotes: 9