I read that the SFP is used to restore EBP to its previous value. Why does EBP needs to return to it's initial value?
Asked
Active
Viewed 6,426 times
0
-
The C language does not even mention a stack, less specific registers. – too honest for this site Jul 14 '17 at 22:06
-
1"The EBP register—sometimes called the frame pointer (FP) or local base (LB) pointer—is used to reference local function variables in the current stack frame. Each stack frame contains the parameters to the function, its local variables, and two pointers that are necessary to put things back the way they were: the **saved frame pointer (SFP)** and the return address. **The SFP is used to restore EBP to its previous value, and the return address is used to restore EIP to the next instruction found after the function call.** " @Olaf – zahlen Jul 15 '17 at 14:25
-
Please provide a reference to the standard defining this register and requiring a C implementation to use a stack at all. Read [ask] and take the [ŧour] to see what tags are for and what a question should contain. – too honest for this site Jul 15 '17 at 14:47
-
because by convention the caller was using it (or we assume that is the case) and expects it to be preserved across the call. – old_timer Jul 15 '17 at 16:15
1 Answers
2
Why does EBP needs to return to it's initial value?
When a function call is made, the compiler typically, as the first thing for the function body, pushes the current EBP value on to the stack and sets the EBP (base pointer/frame pointer) to the current ESP (stack pointer, always points to the top of the stack). Then EBP is used to access local variables and arguments of the function.
The value of EBP is restored when a function returns o that it can serve the function call of the previous function.

haccks
- 104,019
- 25
- 176
- 264