Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 698
venus.w Avatar asked Jan 17 '23 18:01

venus.w


1 Answers

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.

like image 78
Mike Kwan Avatar answered Jan 24 '23 21:01

Mike Kwan