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?
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