简体   繁体   English

GNU内联汇编中的百分号(%)(C中的汇编)

[英]Percentage (%) sign in GNU inline assembly (asm in C)

What these lines of code are supposed to do? 这些代码行应该做什么?

mov ebx, %1

mov ecx, %0

I know that % means pointer but I need some more explanation. 我知道%表示指针,但我需要更多说明。 Why %1 and 0 - these specific numbers? 为什么%1和0-这些特定数字?

In AT&T syntax, registers are refered to using a percent sign and then the registers name, ie %eax . 在AT&T语法中,使用百分号引用寄存器,然后使用寄存器名称即%eax The ones you showed with digits however have no meaning in assembly, they are used in inline assembly to refer to the input and output operands. 用数字显示的那些在汇编中没有意义,它们在内联汇编中用于引用输入和输出操作数。

int i = 5;
int j;
asm ("mov %1, %0" : "=r"(j) : "r"(i)); //AT&T. Swap operands for Intel syntax

This would declare i and j as output and input arguments respectively. 这将分别声明ij为输出和输入参数。 The q means, any general purpose register is fine. q表示任何通用寄存器都可以。 Unless you really need a specific register, you should always let your compiler choose whatever is convenient. 除非确实需要特定的寄存器,否则应始终让编译器选择方便的选项。 Since you don't know beforehand which registers you get, they get assigned a number starting from 0. %0 is the first argument, in this case the output argument j and %1 is the input argument, i . 由于您事先不知道获得哪个寄存器,因此会为它们分配一个从0开始的数字。 %0是第一个参数,在这种情况下,输出参数j%1是输入参数i

%0 and %1 are the first two operands to the inline assembly block. %0和%1是内联汇编块的前两个操作数。 It's not regular x86, but special to gcc, I think. 我认为这不是常规的x86,但对gcc来说很特殊。

See here: http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html 参见此处: http : //www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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