venus.w
venus.w

Reputation: 2251

asm code containing %0,what does that mean?

My asm knowledge is so limited, I need to know the following codes:

movl %%esp %0

Does %0 represent a register, a memory address, or something else? What does the %0 mean?

Upvotes: 6

Views: 8327

Answers (1)

Mike Kwan
Mike Kwan

Reputation: 24447

It represents some input/output operand. It allows you to make use of your C variables in your assembly code. This page has some nice examples.

%0 is just the first input/output operand defined in your code. In practice, this could be a stack variable, a heap variable or a register depending on how the assembly code generated by the compiler.

For example:

int a=10, b;
asm ("movl %1, %%eax; 
      movl %%eax, %0;"
     :"=r"(b)        /* output */
     :"r"(a)         /* input */
     :"%eax"         /* clobbered register */
     );

%0 is b in this case and %1 is a.

Upvotes: 13

Related Questions