1

pop ebp在 IA-32 和 x86-64 机器中,最后在ret代码(返回)指令之前是什么意思?所以我确实有 old 和 new ebp,并且 newebp通过调用函数被推入堆栈。那么这ebppop'ed?指令如何pop改变 的值ebp

4

1 回答 1

2
PUSH EAX

本质上是指:

SUB ESP,4
MOV [ESP],EAX

POP EAX

方法:

MOV EAX,[ESP]
ADD ESP,4

当您谈论新旧时,EBP我猜您指的是功能序言和尾声?

PUSH EBP     ; Store caller's EBP on the stack
MOV EBP,ESP  ; Set EBP to the current stack pointer

; Here we can do things like:
MOV EAX,[EBP+8]
PUSH EAX
MOV EBX,[EBP+12]
POP EAX
; ..to access the stack. Since we've got a fixed reference point for
; the stack in EBP we don't have to worry about the stack pointer
; changing.

; For example, we could do this instead to access the same stack
; elements as above:
MOV EAX,[ESP+8]
PUSH EAX
MOV EBX,[ESP+16]
POP EAX
; But notice that we had to change the second offset since the push
; instruction changed the stack pointer. It's obviously easier to deal
; with a base address that doesn't change every time we execute
; certain instructions.

MOV ESP,EBP  ; Restore the stack pointer
POP EBP      ; Restore the caller's EBP before returning
于 2013-07-05T12:45:32.217 回答