为什么gcc使用movl而不是push来传递函数args? [英] Why does gcc use movl instead of push to pass function args?

查看:162
本文介绍了为什么gcc使用movl而不是push来传递函数args?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意以下代码:

#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

该命令以汇编形式显示我们的源代码.

that command shows our source code in assembly.

现在我们可以在主函数中看到,我们从不使用"push"命令来推入 该函数进入堆栈.它使用"movel"代替了

now we can see in the main function, we never use "push" command to push the arguments of the a function into the stack. and it used "movel" instead of that

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

为什么会发生? 他们之间有什么区别?

why does it happen? what's difference between them?

推荐答案

这是显然,默认情况下启用了-maccumulate-outgoing-args,而覆盖了-mpush-args.在此处使用-mno-accumulate-outgoing-args显式编译确实会恢复为PUSH方法.

Apparently -maccumulate-outgoing-args is enabled by default, overriding -mpush-args. Explicitly compiling with -mno-accumulate-outgoing-args does revert to the PUSH method, here.

2019年更新:自奔腾M以来,现代CPU一直具有高效的推送/弹出功能.
-mno-accumulate-outgoing-args(并使用推送)最终成为2014年1月-mtune=generic的默认设置.

2019 update: modern CPUs have had efficient push/pop since about Pentium M.
-mno-accumulate-outgoing-args (and using push) eventually became the default for -mtune=generic in Jan 2014.

这篇关于为什么gcc使用movl而不是push来传递函数args?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆