Reputation: 964
I am very new to GNU assembly inlining, I have read multiple write ups but still do not fully understand what is going on. From my understanding:
movl %eax, %ebx\n\t
will move whatever is in %eax
into ebx
, but will not add the contents to each other
addl %eax, %ebx\n\t
will add the contents of %eax
with ebx
and keep it at the right most register
addl %1, %0\n\t
this is where i get confused, we are adding 1 and 0? why do we need to have the %0
there?
Upvotes: 3
Views: 3810
Reputation: 71
The whole asm inline block looks like:
asm [volatile] ( AssemblerTemplate
: OutputOperands
[ : InputOperands
[ : Clobbers ] ])
OR
asm [volatile] ( AssemblerTemplate
: OutputOperands)
In the AssemblerTemplate is your assembly code, and in Output/InputOperands, you can pass variable between C and ASM.
Then in Asm, %0 refers to the first variable passed as OutputOperand or InputOperand, %1 to the second, etc.
Example:
int32_t a = 10;
int32_t b;
asm volatile ("movl %1, %0" : "=r"(b) : "r"(a) : );
This asm code is equivalent to "b = a;"
A more detailed explanation is here: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
Upvotes: 6