Home computickets Why do I need an EBP register

Why do I need an EBP register




What is the EBP register, if you have ESP ?

Answer 1, Authority 100%

One of the typical ways to use the register EBP – storage of the basic address stroke frame .

If it is simplified, at the beginning of the function, the status of the register ESP is stored in EBP , and further the addresses of the arguments of the function and local variables are counted from it. Next, during the operation of the function (and the functions caused by it) ESP may vary anything, but the address of the local variable in this function as it was, say, EBP-8 remains For any changes ESP .

When addressing local variables, you can do without ebp , but then the address of the variable will be calculated as ESP + N + VAR , where n depends on what changes have occurred with esp After allocating memory in the stack under local variables. Modern compilers, in general, and do, and EBP use for some other purposes (for example, just as a general-purpose register).

Another addition. In 16-bit times with a challenged addressing (base register + index register + offset, i.e., for example, [BP + Si + 10h] ) as a basic register, it was possible to use only BP and bx (sp could not be used as a basic register, i.e. Addressing of the type [SP + N] is impossible ), as an index – only Si and Di . Therefore, if there were no BP , I would have to do only one basic register (then it would be more logical to be BX Rename in BP (Base Pointer)). With a 32-bit addressing, the separation is not so strict, any 32-bit register can be used as a base register, as an index – anyone except ESP .

Answer 2, Authority 44%

Well, I would have responded – all these general purpose registers, but mainly they are used to work with a stack (although other applications are not excluded); Usually ESP Specifies the current state of the stack , and EBP – the start of the stack frame for this call function, so it does not have to suffer with the addresses of local variables each Change in stack. For example, with additional memory allocation in the stack or something else in such a kind.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions