在gcc中,您可以使用以下语法声明应将局部变量放入寄存器中.
register int arg asm("eax");
Run Code Online (Sandbox Code Playgroud)
在我在互联网上找到的一些旧代码中,这种语法用于声明函数的参数应该在寄存器中传递:
void foo(register int arg asm("eax"))
Run Code Online (Sandbox Code Playgroud)
但是当我尝试这个例子时:
/*
Program to demonstrate usage of asm keyword to allocate register for a variable.
*/
#include <stdio.h>
/* Function with argument passed in register */
void foo(register int arg asm("eax") )
{
register int loc asm("ebx");
loc = arg;
printf("foo() local var: %d\n", loc);
}
int main(void)
{
foo(42);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
用gcc编译我得到一个错误:
gcc main.c -o test-asm.exe
main.c:7:27: error: expected ';', ',' or ')' before 'asm'
Run Code Online (Sandbox Code Playgroud)
现在我的问题是:
上面的asm语法是正确的,在gcc中,对于函数的形式参数是什么? …