Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need a return address?

Tags:

stack

assembly

On a call stack, we have a frame pointer which gives us the location of the arguments to a procedure and the address of a pointer to the previous frame. We also have a return address. Why it the return address necessary? Could we not just follow the frame pointers back up the stack, popping off the stack frames as we went? Is the return address just an optimisation?

like image 252
N. McA. Avatar asked Dec 22 '25 19:12

N. McA.


1 Answers

The return address does not point to the previous stack frame, it points into the code segment to the next instruction in the calling method.

like image 181
Thilo Avatar answered Dec 24 '25 10:12

Thilo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!