这些寄存器为什么被推入堆栈?

问题描述:

push %ebp 
push %esp, %ebp 
push edi 
push esi 
push ebx 

(x86 32位系统的Linux)这些寄存器为什么被推入堆栈?

为什么这些寄存器压入堆栈?
由于某种原因迁移...?
但是,为什么只有'edi''esi''ebx'被推送?

+2

您正在寻找的关键字是[ABI](https://en.wikipedia.org/wiki/Application_binary_interface),特别是[调用约定](https://en.wikipedia.org/wiki/Calling_convention )。 – 2012-03-21 01:15:28

这是x86代码生成器的gcc实现细节。令人惊讶的是很难找到好的文档,我确实发现this page这非常准确。关键部分:

ret指令后:

%eip contains return address 
%esp points at arguments pushed by caller 
called function may have trashed arguments 
%eax contains return value (or trash if function is void) 
%ecx, %edx may be trashed 
%ebp, %ebx, %esi, %edi must contain contents from time of call 

的“必须包含通话时间内容”这句话解释了为什么他们在函数序言推,并在结尾再次弹出。

+0

加上“%eax,%ecx,%edx是”呼叫者保存“寄存器” – mctylr 2012-03-21 01:59:28

+0

非常感谢你! – hk0xwz 2012-03-21 02:07:05