第58部分- Linux x86 64位彙編内聯彙編使用記憶體位置
内聯彙編中使用寄存器比使用記憶體要快,但是也可以直接使用C變量的記憶體位置的。限制為m.
示例
#include <stdio.h>
int main()
{
int dividend = 20;
int divisor = 5;
int result;
asm("divb %2\n\t"
"movl %%eax, %0"
: "=m"(result)
: "a"(dividend), "m"(divisor));
printf("The result is %d\n", result);
return 0;
}
gcc -o memtest memtest.c
asm代碼段中将被除數放到了eax寄存器中,除數放到記憶體位置中,值被加載到記憶體位置中。