的C函数调用公约:为什么MOVL不是pushl? [英] C Function Call Convention: Why movl instead of pushl?

查看:242
本文介绍了的C函数调用公约:为什么MOVL不是pushl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么以下线使用 MOVL 推栈指针下面的数据是由GCC产生的。

I don't understand why the following lines are using movl to push data below the stack pointer are produced by GCC.

movl    -4(%ebp), %eax      # -4(%ebp) <- local variable 1
movl    8(%ebp), %edx       # 8(%ebp)  <- first parameter
movl    %edx, 8(%esp)       # ??? WHY NOT:   pushl %edx
movl    %eax, 4(%esp)       # ??? WHY NOT:   pushl %eax
movl    -8(%ebp), %eax      # ??? WHY NOT:   pushl -8(%ebp)
movl    %eax, (%esp)
call    athena
movl    %eax, f

(满code)

我想这code试图推动3个参数的函数调用。但是,为什么是不是使用 pushl 。这是什么code的使用和如何工作的?

I guess this code tries to push 3 parameters for the function call. But why isn't it using pushl. What is the usage of this code and how does this work?

推荐答案

汉斯帕桑特正确回答。推/弹出运算codeS可以分解成两个微操作里面做一个存储器移动和堆栈指针的递增/递减。如果堆栈指针 - 或任何指针 - 更新,然后立即在接下来的运算code使用,执行失速一般发生。通过堆栈指针访问单个存储位置 - 在你的榜样 - 就没有停止和操作可能会配对,让他们可以同时执行

Hans Passant answered correctly. The push/pop opcodes can be broken down into two micro-ops which do a memory move and an increment/decrement of the stack pointer. If the stack pointer - or any pointer - is updated and then immediately used in the next opcode, an execution stall generally occurs. By accessing the individual memory locations through the stack pointer - as in your example - there would be no stall and the operations could be paired allowing them to be executed simultaneously.

任何超标量CPU类型将尝试在一个周期内执行多个操作codeS,如果他们的结果/来源无关彼此。编译器做的东西给你,以加快执行,这将是相当费力的做手工。运codeS可能会占用更多的空间比推,但他们将执行大约两倍的速度 - 在其他条件相同的

Any superscalar CPU type will attempt to execute multiple opcodes in a single cycle if their results/sources have nothing to do with one another. The compiler is doing something for you to speed up execution that would be fairly laborious to do by hand. The opcodes may occupy more space than pushes, but they will execute roughly twice as fast - all other things being the same.

这篇关于的C函数调用公约:为什么MOVL不是pushl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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