推入和弹出在组装中如何工作 [英] how does push and pop work in assembly

查看:80
本文介绍了推入和弹出在组装中如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对pop在组装中的实际用途感到困惑. pop是将值PUSH ed最后移到堆栈上(这意味着如果我们MOV最后一个元素PUSH ed之后​​的值不适用)还是仅弹出最后一个在堆栈上的值?堆栈(因此,同时应用于MOVPUSH),还是会弹出堆栈指针所指向的值?考虑以下代码:

I'm getting confused on what does pop actually do in assembly. Does pop move the value PUSHed onto the stack last (meaning it doesn't apply if we MOV a value after the the last element PUSHed) 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆