什么是EBP在以下code的目的是什么? [英] What is the purpose of EBP in the following code?

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

问题描述

我对EBP寄存器中的两个问题。

我理解ESP和EIP。不过,我真的不明白为什么人们会使用EBP。

在下面的code,我推EBP寄存器(实际上是0000000)堆栈。我然后移动堆栈EBP的存储器地址,以便ESP和EBP具有相同的数据。这是序言。在有一些code这与系统调用完成。然后,我做反向(收尾)为假表示我谨EBP到ESP(这些值是相同的感谢序言),然后弹出堆栈中的最后一个值(这是EBP是00000000),以EBP。这给EBP序言之前,如发生相同的值。

为什么会有人这样做?要点是什么?请回答一个简单的方法!请记住,我不掌握什么EBP(帧指针)实际执行。

编辑:或者是它,这是一种能够有效备用栈(ESP)中的函数时?换言之:程序可以做什么,它与堆栈和原栈确实将永远存在的EBP。在程序完成时。然后,EBP放回到它以前的样子。它是否正确?如果是这样,收尾只是一个整理程序?

另外,AIUI,我可以用'输入'来代替'推EBP / MOV EBP,ESP。然而,当我尝试在NASM编译,我得到错误:OP code的组合无效和操作数''假'工作正常; ENTER没有。什么是正确的语法?

谢谢!

 示例:    推EBP
    MOV,EBP,ESP    [一些code这里]
    INT 0x80的离开
RET


解决方案

EBP的想法的确是形成一个参考固定点。通常情况下,你可能会摆弄有关堆栈指针(例如同时推动参数压入栈准备通话),并发现这是一个真正的痛苦,以找出其中某些数据是相对于堆栈指针。但相对于底座指针它始终是相同的。现代编译器有没有困难的工作了这一点,但是如果你想写一大块汇编code(用手),使用的堆栈压入和弹出,你会发现更容易引用您相对于局部变量注册(EBP)不改变。

I have two questions about the EBP register.

I understand ESP and EIP. However, I don't really understand why one would use EBP.

In the code below, I push the EBP register (which is actually 0000000) to the stack. I then move the memory address of the stack to EBP so that ESP and EBP have the same data. This is the prolog. The there is some code which finishes with the syscall. Then I do the reverse (the epilog) as 'leave' indicates that I move EBP to ESP (these values are the same thanks to the prolog) then pop the last value of the stack (which is EBP which is 00000000) to EBP. This gives EBP the same value as happened before the prolog.

Why would anyone do this? What is the point? Please answer in a simple way! Remember that I do not grasp what EBP (the frame pointer) actually does.

EDIT: or is it that this is a way to effectively backup the stack (ESP) when in a function? In other words: the program can do what it does with the stack and the 'original stack' will always be there in EBP. Then when the program finishes, EBP is put back to how it was before. Is this correct? If so, the epilog is just a tidying up routine?

Also, AIUI, I can use 'enter' to replace 'push ebp / mov ebp, esp'. Yet when I try to compile in nasm, I get 'error: invalid combination of opcode and operands' 'leave' works fine; 'enter' does not. What is the correct syntax?

Thanks!

Example:

    push ebp
    mov, ebp, esp 

    [some code here]
    int 0x80

leave
ret   

解决方案

The idea of EBP is indeed to form a fixed point of reference. Often you may fiddle about with the stack pointer (e.g. while pushing parameters onto the stack ready for a call) and find it a real pain to figure out where some piece of data is relative to the stack pointer. But relative to the base pointer it is always the same. Modern compilers have no difficulty working this out, but if you wanted to write a big piece of assembler code (by hand) that uses the stack for pushing and popping, you would find it easier to reference your local variables relative to a register (EBP) that does not change.

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

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