推入和弹出在组装中如何工作 [英] 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)
这篇关于推入和弹出在组装中如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!