为什么在我的GCC输出额外的指令? [英] Why are there extra instructions in my gcc output?
本文介绍了为什么在我的GCC输出额外的指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
GCC编译(使用 GCC --omit帧指针-S
)
int the_answer() { return 42; }
到
.Text
.globl _the_answer
_the_answer:
subl $12, %esp
movl $42, %eax
addl $12, %esp
ret
.subsections_via_symbols
什么是'$ 12'不断在这里做什么,什么是'%ESP注册?
What is the '$12' constant doing here, and what is the '%esp' register?
推荐答案
简短的回答:。栈帧
龙回答:当你调用一个函数,编译器将操作堆栈指针,以便本地数据,如函数变量。由于您的code正在改变尤其
,堆栈指针,这就是我认为这里发生了什么。我本来以为GCC足够聪明,它不是实际需要来优化这个了,但您可能无法使用优化。
Long answer: when you call a function, compilers will manipulate the stack pointer to allow for local data such as function variables. Since your code is changing esp
, the stack pointer, that's what I assume is happening here. I would have thought GCC smart enough to optimize this away where it's not actually required, but you may not be using optimization.
这篇关于为什么在我的GCC输出额外的指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文