I came across a code that looks like this:
asm volatile (
# [...]
"movl $1200, %%ecx;"
# [...]
);
I know what movl $1200, %ecx
does in x86. but I was confused by why there are two percent signs.
The lines with "r" or "=r" are operand constraints. The "=" means output operand. Essentially, this: :"=r"(y) :"r"(x) means that %0 (ie: the first operand) corresponds to y and is for output, and %1 (the second operand) corresponds to x.
this reads the value of the register and stores it in the value variable. The other example uses ::"r" asm volatile ("MSR PMUSERENR_EL0, %0\n":: "r"(value)); This writes the value variable to the PMUSERENR_ELO register. Here is another example of it:How to measure program execution time in ARM Cortex-A8 processor?.
GCC inline assembly uses %0, %1, %2, etc. to refer to input and output operands. That means you need to use two %% for real registers.
Check this howto for great information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With