什么是 ESP 和 EBP 寄存器? [英] What are the ESP and the EBP registers?

查看:28
本文介绍了什么是 ESP 和 EBP 寄存器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现ESP寄存器是当前堆栈指针,EBP是当前堆栈帧的基指针.但是,我不明白这些定义(我刚刚开始学习如何在汇编程序中编码).

I found that the ESP register is the current stack pointer and EBP is the base pointer for the current stack frame. However, I don't understand these definitions (I am just starting to learn how to code in assembler).

据我所知,ESP 指向堆栈本身,而 EBP 指向堆栈顶部的任何内容1.但这些只是我的猜测,它们很可能是不正确的.否则,下面这样的语句是什么意思?

What I understand is that ESP points towards the stack itself and EBP points towards whatever is on top of the stack1. But these are just my guesses and they are most likely incorrect. Otherwise, what would a statement like the following mean?

MOV EBP, ESP    

脚注 1:编者注:是的,这是不正确的.在标准术语中,栈顶"是 ESP 指向的地方,即使它是栈帧中的最低地址.类似于向上增长的堆栈数据结构,即使 x86 上的调用堆栈(与大多数 ISA 一样)向下增长.

Footnote 1: Editor's note: Yes, that's incorrect. In standard terminology, the "top of the stack" is where ESP points, even though it's the lowest address in the stack frame. By analogy to a stack data structure that grows upward, even though the callstack on x86 (like most ISAs) grows downward.

推荐答案

esp 是栈指针,ebp 是/曾经是栈帧,这样当你进入一个函数时 ebp 可以在那个点得到一个 esp 的副本,一切在此之前的堆栈上,返回地址、传入参数等以及该函数的全局事物(局部变量)现在将在函数的持续时间内与堆栈帧指针保持静态距离.esp 现在可以根据编译器的需要自由地四处游荡,并且可以在嵌套到其他函数时使用(每个函数都需要自然地保留 ebp).

esp is the stack pointer, ebp is/was for a stack frame so that when you entered a function ebp could get a copy of esp at that point, everything on the stack before that happens, return address, passed in parameters, etc and things that are global for that function (local variables) will now be a static distance away from the stack frame pointer for the duration of the function. esp is now free to wander about as the compiler desires and can be used when nesting to other functions (each needs to preserve the ebp naturally).

这是一种管理堆栈的懒惰方式.使编译器调试更容易,更容易理解编译器生成的代码,但会烧掉一个原本可能是通用的寄存器.

it is a lazy way to manage the stack. makes compiler debugging a lot easier, makes understanding the code generated by the compiler easier, but burns a register that might have been otherwise general purpose.

这篇关于什么是 ESP 和 EBP 寄存器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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