有人可以提供与gcc一起使用fastcall的示例吗?如果可能的话,您可以在不使用fastcall的情况下提供等效调用,并说明它们的不同之处?

最佳答案

给定函数调用在C代码中出现的方式没有什么不同。唯一的区别是在函数声明中。 GCC manual有更多详细信息。

$ cat fastcall.c
extern void foo1(int x, int y, int z, int a) __attribute__((fastcall));
extern void foo2(int x, int y, int z, int a);

void bar1()
{
    foo1(99, 100, 101, 102);
}

void bar2()
{
    foo2(89, 90, 91, 92);
}

$ gcc -m32 -O3 -S fastcall.c -o -
.
.
bar1:
.
.
    movl    $100, %edx
    movl    $99, %ecx
    movl    $102, 4(%esp)
    movl    $101, (%esp)
    call    foo1
.
.
bar2:
.
.
    movl    $92, 12(%esp)
    movl    $91, 8(%esp)
    movl    $90, 4(%esp)
    movl    $89, (%esp)
    call    foo2

关于c - Fastcall GCC示例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/672268/

10-11 15:13