【问题标题】:Why are these registers pushed to stack?为什么这些寄存器被推入堆栈?
【发布时间】:2012-03-21 09:56:02
【问题描述】:
push    %ebp
push    %esp, %ebp
push    edi
push    esi
push    ebx

(x86 32bit Linux)

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

【问题讨论】:

标签: assembly


【解决方案1】:

它是 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 

“必须包含调用时的内容”短语解释了为什么它们被推送到函数序言中并在结尾处再次弹出。

【讨论】:

  • 加上“%eax, %ecx, %edx 是“调用者保存”寄存器”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-28
  • 2015-12-13
  • 2018-04-17
  • 2012-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多