Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 帧指针、epb和返回地址_Assembly_Windbg_Callstack_Calling Convention - Fatal编程技术网

Assembly 帧指针、epb和返回地址

Assembly 帧指针、epb和返回地址,assembly,windbg,callstack,calling-convention,Assembly,Windbg,Callstack,Calling Convention,下图来自调用堆栈上的wikipedia,有一点我不完全理解: 我认为存储在ebp寄存器中的帧指针在序言中被初始化为这样*: push ebp ; Preserve current frame pointer mov ebp, esp ; Create new frame pointer pointing to current stack top sub esp, 20 ; allocate 20 bytes worth of locals on stack. 如果是这样的话,那么图像

下图来自调用堆栈上的wikipedia,有一点我不完全理解:

我认为存储在ebp寄存器中的帧指针在序言中被初始化为这样*:

push ebp  ; Preserve current frame pointer 
mov ebp, esp ; Create new frame pointer pointing to current stack top 
sub esp, 20 ; allocate 20 bytes worth of locals on stack. 
如果是这样的话,那么图像中的帧指针不应该指向返回地址之后,它应该是前一个帧指针地址之前,返回地址之前吗?我错过了什么

谢谢


*摘自:

是的,您是对的,帧指针指向存储在返回地址之前的前一帧指针的地址。正确的图片应该是

               | locals
               +---------
frame pointer->| prev frame pointer
               +--------
               | return address
               +--------

当函数被调用时。返回地址被推送到堆栈上,堆栈指针现在指向返回地址。 这是函数内部发生的情况:

push ebp  ; Push the ebp; The ebp address will pushed on stack and sp will be decremented
mov ebp, esp ;  EBP will now point the same as ESP which is previous value of EBP
sub esp, 20 ;    ESP will be subtracted further to create frame for local variables
结果是: EBP指向EBP的上一个值。
ESP指向ESP的另外20个字节。这20个字节将用于本地变量。

谢谢-这是否意味着ESP实际上没有指向堆栈的顶部,而是指向堆栈中的最后一项?@SpeksETC:最后一项位于堆栈的顶部