【发布时间】:2013-05-17 05:17:53
【问题描述】:
我是组装新手,然后我遇到了这个article
上面写着这段代码
void MyFunction()
{
int a, b, c;
a = 10;
b = 5;
c = 2;
等价于这个
push ebp ; save the value of ebp
mov ebp, esp ; ebp now points to the top of the stack
sub esp, 12 ; space allocated on the stack for the local variables
mov [ebp - 4], 10 ; location of variable a
mov [ebp - 8], 5 ; location of b
mov [ebp - 12], 2 ; location of c
根据这个video,要访问基指针上方的堆栈值,我们应该添加。如果它低于指针,我们应该减去。鉴于上面的例子,他们从基指针中减去了一些东西来移动所需变量的位置,这与视频中的说明相反。
我错过了什么?我知道 sub esp, 12 正在为局部变量分配空间,所以我想到的是 EBP 低于该分配,所以我认为它应该是 [ebp + something] 而不是减号。
所以当他执行这个 sub esp, 12 时,堆栈就是这样的。
ESP is here
| 2 | Ebp + 12
| 5 | Ebp + 8
| 4 | Ebp + 4
| | Old EBP value
文章是错的,还是我误解了?
【问题讨论】:
标签: assembly masm stack-frame