I'm not sure what this inline assembly does:
我不确定这个内联汇编是做什么的:
asm ("mov %%esp, %0" : "=g" (esp));
especially the : "=g" (esp)
part.
特别是:“= g”(特别是)部分。
2 个解决方案
#1
9
"=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
.
“= g”(esp)定义内联汇编的输出。 g告诉编译器它可以使用任何通用寄存器或存储器来存储结果。 (esp)表示结果将存储在名为esp的c变量中。 mov %% esp,%0是汇编命令,它只是将堆栈指针移动到第0个操作数(输出)。因此,该程序集只是将堆栈指针存储在名为esp的变量中。
#2
9
If you want the gory details, read the GCC documentation on Extended Asm.
如果您需要详细信息,请阅读有关Extended Asm的GCC文档。
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.)
简短的回答是,它将x86堆栈指针(%esp寄存器)移动到名为“esp”的C变量中。 “= g”告诉编译器它可以用什么类型的操作数代替汇编代码中的%0。 (在这种情况下,它是一个“通用操作数”,这意味着几乎允许任何寄存器或内存引用。)
#1
9
"=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
.
“= g”(esp)定义内联汇编的输出。 g告诉编译器它可以使用任何通用寄存器或存储器来存储结果。 (esp)表示结果将存储在名为esp的c变量中。 mov %% esp,%0是汇编命令,它只是将堆栈指针移动到第0个操作数(输出)。因此,该程序集只是将堆栈指针存储在名为esp的变量中。
#2
9
If you want the gory details, read the GCC documentation on Extended Asm.
如果您需要详细信息,请阅读有关Extended Asm的GCC文档。
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.)
简短的回答是,它将x86堆栈指针(%esp寄存器)移动到名为“esp”的C变量中。 “= g”告诉编译器它可以用什么类型的操作数代替汇编代码中的%0。 (在这种情况下,它是一个“通用操作数”,这意味着几乎允许任何寄存器或内存引用。)