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?
In AT&T syntax, registers are refered to using a percent sign and then the registers name, ie %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. The q
means, any general purpose register is fine. 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 and %1 are the first two operands to the inline assembly block. It's not regular x86, but special to gcc, I think.
See here: http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html
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.