Request for using stack pointer in assembly language

I was ready to publish a wikipedia article on tail recursion: http://en.wikipedia.org/wiki/Tail_call

Now, at the end of the article, the example shows that the stack pointer is used to access the arguments passed to the function call in the assembly pseudo-code. Is that not so? I mean, what arguments are called by the called user using the frame pointer on the right, and not the stack pointer?

+4
source share
2 answers

Using the stack pointer is fine. He always points to the stack in the end. It's a little difficult to track offsets from the stack pointer to function arguments if the function has any push or pop commands. And it's really hard to move the stack back to the debugger when there is no pointer to the frame.

Using a frame pointer makes it easier for the debugger and compiler writer to work, but it is not necessary to have one.

Setting the frame pointer takes an instruction, and it uses a register that could potentially be used for other purposes. Therefore, using a stack pointer is a general method for optimizing code. Microsoft compilers even have a name for this optimization, they call it Frame Pointer Failure

+4
source

A dedicated frame pointer register is by far the more popular generally accepted ABI calling convention, but there is nothing "wrong" to use another (possibly simpler) calling convention when it's pure for illustrative purposes (adding a frame pointer register to these fragments will just make them a little longer and will not change anything).

+3
source

Source: https://habr.com/ru/post/1302826/


All Articles