注意这段代码:
#include <stdio.h>
void a(int a, int b, int c)
{
char buffer1[5];
char buffer2[10];
}
int main()
{
a(1,2,3);
}
在那之后 :
gcc -S a.c
该命令显示了我们的汇编源代码。
现在我们可以看到在主函数中,我们从不使用“push”命令来推送参数
将a函数放入栈中。它使用“移动”代替
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $16, %esp
movl $3, 8(%esp)
movl $2, 4(%esp)
movl $1, (%esp)
call a
leave
为什么会发生这种情况?
他们之间有什么区别?
这是什么海湾合作委员会手册不得不说一下:
-mpush-args
-mno-push-args
Use PUSH operations to store outgoing parameters. This method is shorter and usually
equally fast as method using SUB/MOV operations and is enabled by default.
In some cases disabling it may improve performance because of improved scheduling
and reduced dependencies.
-maccumulate-outgoing-args
If enabled, the maximum amount of space required for outgoing arguments will be
computed in the function prologue. This is faster on most modern CPUs because of
reduced dependencies, improved scheduling and reduced stack usage when preferred
stack boundary is not equal to 2. The drawback is a notable increase in code size.
This switch implies -mno-push-args.
显然-maccumulate-outgoing-args
默认启用,覆盖-mpush-args
。显式编译-mno-accumulate-outgoing-args
确实恢复到PUSH
方法,这里。
2019年更新:自 Pentium M 以来,现代 CPU 就具有高效的推送/弹出功能。
-mno-accumulate-outgoing-args
(并使用推送)最终成为默认设置-mtune=generic
2014 年 1 月。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)