AT& T中的汇编程序寻址

时间:2013-06-11 14:58:05

标签: assembly

任何人都可以帮助我理解这个命令:

mov %esp,%edi

lea 0x10(%edi),%esi

首先我将esp的地址加载到edi。 然后我加载edi+10的值,即esp+10esi的地址。 但这对堆栈意味着什么呢?如果我按下,我会在堆栈上写4个字节,对吧?如果我将10字节跳回到我的堆栈上,这一点在哪里?

|______|         # here?
|______|
|______|
|______|
|______|
|______|
|______|
|___*__|         # or at the position of the star?
|______|         # 4 Byte
|______|         # also 4 Byte long...
|______|   <---%edi

1 个答案:

答案 0 :(得分:0)

你在x86上,而不是x64,对吗?我会假设这一点。

“这对堆栈意味着什么?”

mov %esp,%edi
lea 0x10(%edi),%esi

此代码对您的堆栈操作(pushpop等没有影响。那是因为堆栈操作在esp寄存器上作为堆栈指针。上面的代码不会改变esp,所以就堆栈而言,没有任何改变。

“如果我按下,我会在堆栈上写4个字节,对吧?”:

不一定。 x86支持对16位和32位操作数进行推送操作,因此写入堆栈的字节数取决于您所推送的大小。例如:

push %ax  ; will push 2 bytes on the stack (sizeof(ax) == 2)
push %eax ; will push 4 bytes on the stack (sizeof(eax) == 4)

请注意,推送也会esp减去sizeof(op1)

“如果我在我的堆栈上跳回10个字节,这一点在哪里?”

lea上的esi命令不会更改堆栈指针。所以,

nop                   ; 10 points back on the stack here
mov %esp,%edi       
lea 0x10(%edi),%esi
nop                   ; will be the exact same location as here.
                      ; relative to esi, this location is (esi - 26)