Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a double-percent sign (%%) do in gcc inline assembly?

Tags:

c

x86

gcc

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.

like image 248
UXkQEZ7 Avatar asked Feb 07 '13 07:02

UXkQEZ7


People also ask

What does R mean in inline assembly?

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.

What is r in assembly language?

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?.


1 Answers

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.

like image 96
Carl Norum Avatar answered Oct 23 '22 17:10

Carl Norum