【发布时间】:2018-02-22 05:13:57
【问题描述】:
我对 ebp 和 esp 的使用与在 x86 汇编语言中设置堆栈帧的关系有些困惑。在以下代码中:
section '.code' code readable executable ; define the code section of the file
main: ;main label is where execution begins
push ebp
mov ebp,esp ;set up the base ptr
sub ebp,4 ;subtract 4 from ebp
mov dword [esp],msg
call [printf]
mov dword [esp],p ; pass pause>nul cmd to system to hold the box open
call [system]
mov dword [esp],0 ;pass NULL to exit
call [exit]
程序员从 ebp 中减去了 4,但我不知道为什么。通常,我在这里看到的是 ESP 的减法,而不是 EBP。这里从 EBP 中减去的目的是什么?
【问题讨论】:
-
这段代码还有更多内容吗?或者这是整个sn-p?就这里具体发生的事情而言......他们使用堆栈指针将参数传递给他们调用的函数(而不是
push'ing他们到堆栈他们只是将数据直接移动到堆栈)。 -
@SimonWhitehead 不,先生,这是整个程序没有 .data 和 .idata 部分,其中声明了使用的变量和导入
-
我想我明白你在说什么......所以基本上,他们将 msg 的内存地址(因此 ptr 为 4 个字节)放入从 ebp 中减去的 4 个字节中?
-
SO 替代方案是
sub esp, 4,然后是push msg? -
我认为它没有任何实际用途。这个sn-p挺奇怪的。
标签: assembly x86 fasm stack-frame