What does the g = "g" sign in GCC inline assembly means / do?

I'm not sure what this inline assembly does:

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

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

+6
source share
2 answers

"=g" (esp) defines the output for the inline assembly. g tells the compiler that it can use any general register or memory to store the result. (esp) means that the result will be saved in a variable c named esp . mov %%esp, %0 is a build command that simply moves the stack pointer to the 0th operand (output). Therefore, this assembly simply stores the stack pointer in a variable called esp .

+9
source

If you need gory details, read the GCC documentation on Extended Asm .

The short answer is that this moves the x86 stack pointer (% esp register) to a C variable called "esp". "= G" tells the compiler which types of operands it can replace %0 in the assembly code. (In this case, it is a "shared operand", which means that almost any register or memory reference is allowed.)

+9
source

Source: https://habr.com/ru/post/890316/


All Articles