【发布时间】:2014-07-08 05:57:20
【问题描述】:
我正在阅读这本书,它说(根据这个调用约定)它是这样做的:
注意:
The function looks like this:
function( int a, int b)
The function call looks like this:
function(2, 1)
push arguments for function a and b backwards onto the stack
function is called, and ret is "placed" onto the stack
Prolog is executed
EBP is pushed onto stack
Variables local to the function are pushed onto the stack
这就是它告诉我堆栈在这一点上的样子:
Low Memory
b
a
Ret
EBP
array
High memory
我的问题是(因为堆栈会向下增长内存地址):
为什么当 a 和 b 是最先被压入堆栈的东西时,它们在顶部?为什么数组在这么高的地址? “向后推入堆栈”是什么意思?
按照书上的汇编语言是这样的:
sub 0x8, esp
sub 0x8, esp
push 0x2
push 0x1
然后在反汇编函数里面说:
push ebp
这是我真正感到困惑的地方,因为执行了 3 个推送命令,这到底是怎么把 ebp 放在 a 和 b 之前的?
【问题讨论】:
-
Low Memory和High memory在您的图中颠倒了,并且堆栈框架设置代码错误。此外,此堆栈帧结构完全依赖于编译器并受操作系统约束。例如。如果您查看现代 gcc 堆栈框架,它们在很多时候不会像这样工作。现代 Windows 64 位框架有额外的花里胡哨。看来这本书很烂。 -
谢谢。我很感激。
标签: assembly