小编j.k*_*son的帖子

如何使用gcc asm关键字在寄存器中传递函数参数

在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中,对于函数的形式参数是什么? …

c assembly gcc parameter-passing calling-convention

9
推荐指数
1
解决办法
4422
查看次数

标签 统计

assembly ×1

c ×1

calling-convention ×1

gcc ×1

parameter-passing ×1