push 和 pop 在装配中是如何工作的 [英] how does push and pop work in assembly
问题描述
我对 pop
在汇编中的实际作用感到困惑.pop
是否将最后一个 PUSH
ed 的值移动到堆栈上(这意味着如果我们 MOV
在最后一个元素之后的一个值PUSH
ed) 或者它只是弹出堆栈中最后一个值(因此,适用于 MOV
和 PUSH
),或者它是否弹出堆栈指针所指向的值是什么?考虑以下代码:
I'm getting confused on what does pop
actually do in assembly. Does pop
move the value PUSH
ed onto the stack last (meaning it doesn't apply if we MOV
a value after the the last element PUSH
ed) or does it just pop whatever value that's last on the stack (thus, applying to both MOV
and PUSH
), or does it pop what ever value pointed to by the stack pointer? Consider the following code:
push $4
mov $5, -4(%esp)
add $4, %esp (esp pointing to an unknown value)
pop %ebp
那么在这段代码中,ebp
中弹出的值是 4、5,还是 esp
指向的未知值?
So in this code will the value poped into ebp
be 4, 5, or the unknown value pointed to by esp
?
推荐答案
后者
POP EBP
相当于
MOV EBP, [ESP]
ADD ESP, 4 ; but without modifying flags, like LEA ESP, [ESP+4]
(在 Intel 语法中 - 目标在左边,源在右边)
(in Intel syntax - target on the left, source on the right)
这篇关于push 和 pop 在装配中是如何工作的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!