Hi ,
Im trying to understand very deeply what's going with stack frame in terms of stack param storing once calling the function , even more complex on recursion case.

As understand once we call a function then stack frame is created and such parameters are stored :
  • Return address of caller function - on other words stack pointer of the instruction is where caller function stops on the code line when calling other function.
  • Input params.
  • Local Variables.


following are some related concerns to what's explained above :

First query #1 :

assume I have only main function then stack frame for it is ofcourse created .. now my concern is what is the return address stored on the stack frame of main() function?

First query #2 :

If I have a recursive function, each call to the function creates a new stack frame. For instance, if I call the function 10 times (f1, f2, ..., f10), the there will be 10 stack frames for same function because its recursive .. and let's assume each function is called at the same line of code marked by a red as you see on the example below, I am concerned about the return address stored on the stack frame of each recursive call since each call stops at the same line of code, I wonder if the return address stored on the stack frame is the same for all the recursive calls?

Code:
int foo(int a)
{
     if (a>1)
        {
            a = foo(a/2);
         }
     return a;
}

Third query #3 :

the return address is actually the register $ra or $esp on assembly language ... Yes?



Thanks much.