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.
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.
It depends
if there is a colon
:
after the string, then it is an extended asm, and%%
escapes the percent which could have especial meanings as mentioned by Carl. Example:otherwise, it will be a compile time error, because without colon it is a basic asm which does not support variable constraints and does not need or support escaping
%1
. E.g.:works just fine.
Extended asm is more often used since it is much more powerful.
This helps GCC to distinguish between the operands and registers. operands have a single % as prefix. '%%' is always used with registers.
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.