4

I was ready a article posted on wikipedia on Tail recursion: http://en.wikipedia.org/wiki/Tail_call

Now here at the end of the article, the example shows Stack Pointer being used to access the arguments passed to the function call in the assembly pseudo code. Isn't this wrong? I mean the arguments are accessed by the callee by using the frame pointer right rather than the stack pointer?

2 Answers 2

4

Using the stack pointer is fine. It always points to the stack after all. It's just a little difficult to keep track of offsets from the stack pointer to the function arguments if there are any push or pop instructions in the function. And it's really hard to walk the stack back in the debugger when there is no frame pointer.

Using a frame pointer make the job of the debugger and the compiler writer easier, but it's not necessary to have one.

Setting up the frame pointer takes an instruction, and it uses up a register that could potentially be used for other things. So using the stack pointer instead is a common technique for optimizing code. The Microsoft compilers even have a name for this optimization, they call it Frame Pointer Omission

Sign up to request clarification or add additional context in comments.

4 Comments

John, just a quick question. When you say the job of a debugger gets easy with the Frame pointer, which debugger are you talking about?
Any debugger. When you have frame pointers, it's easy to reconstruct the call stack and show it in a debug window. Without frame pointers, the debugger has to actually decompile the code in order to display a call stack.
OOhhkie .. So basically debuggers on Windows will alwaya have more job to do. Any idea about Linux if it uses Frame pointer?
I's not really an OS decision, the compiler chooses whether to use a frame pointer or not, and it could choose differently for each function if it wanted to. Use of the frame pointer is pretty standard when compiler optimizations are turned off. But I really don't know for sure.
3

A dedicated frame pointer register is definitely a more popular calling convention in common ABIs, but there's nothing intrinsically "wrong" in using a different (possibly simpler) calling convention when it's purely for illustrative purposes (adding a frame pointer register to those snippets would just make them a tad longer and change nothing substantial).

1 Comment

thanks for the information. This site is the best in the block right now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.