Activation Records

1) The activation record stores the return address for this function call, and also the parameters, local variables, and the function’s return value, if non-void. It is pushed onto typically an "Activation Stack Record (run-time stack)".

2)The activation record for a particular function call is popped off the run-time stack when the final closing brace in the function code is reached, or when a return statement is reached in the function code.

3)At this time the function’s return value, if non-void, is brought back to the calling block return address for use there.

Example

Suppose we have the following recursive function.....
and we call it with the invokation:

x = Func(5, 2); // original call is instruction 100

// Another recursive function 
int  Func   (  int  a, int b )	
	
	//  Pre:    a and  b have been assigned values
	//  Post:   Function value = ??

{
   int  result;
	if  ( b == 0 ) 	                  //  base case
		result = 0;
	else if  ( b > 0 )                //  first  general  case

		result = a +  Func ( a , b - 1 ) ) ;   // instruction  50

	else 			          //  second general case
		result = Func ( - a , - b ) ;   // instruction 70

   return  result;
} 	







 

© Lynne Grewe