简体   繁体   中英

What does equals sign g “=g” in GCC inline assembly mean / do?

I'm not sure what this inline assembly does:

asm ("mov %%esp, %0" : "=g" (esp));

especially the : "=g" (esp) part.

"=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 .

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM