What is r () and double percent %% in GCC inline assembler language?

Example:

int main(void)
{
    int x = 10, y;

    asm ("movl %1, %%eax;"
        "movl %%eax, %0;"
        :"=r"(y)    /* y is output operand */
        :"r"(x)     /* x is input operand */
        :"%eax");   /* %eax is clobbered register */
}
  • what r(y)?
  • also why is %%used up eax? Usually used single %?
+5
source share
4 answers

Well, this is gcc built-in assembler, which is very powerful, but hard to understand.

First,% char is a special char. It allows you to define registers and placeholders for numbers (mor on this later). Unfortunately,% is also used as part of the register name (for example,% EAX), so in gcc inline assembler you must use two percent of the characters if you want to name the register.

% 0,% 1 % 2 (ect..) -. , . % 0 y, % 1 x. , , asm-, , , .

, r (y): , y % 1 ( , ). . m , , . gcc.

. ! , , ect, (, EAX ). , , , , , .

, , . X EAX. EAX , y. , :

y = x;

: Intel-: . - , , - , . Intel .

+4

"r" "= r" . "=" . , :

:"=r"(y)
:"r"(x)

, % 0 (.. ) y , % 1 ( ) x.

% AT & T, % (:% 0,% 1), double%. , double% printf, % .

- , . , eax . gcc , , - eax, .

+1

, - , - , . , , - .

asm , , , , ; ( ), , , , . , , . , , , .

0

Try this tutorial . It covers everything that you ask: for example, try section 6 - this explains the limitations quite well, and for what the "=" sign stands. Even the concept of interwoven registers is considered (section 5.3).

0
source

All Articles