Program activation records

4,756 views

Published on

Function Calls and Program Activation records / Stack Frames

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,756
On SlideShare
0
From Embeds
0
Number of Embeds
94
Actions
Shares
0
Downloads
78
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Program activation records

  1. 1. Nitin Reddy Katkamnitinkatkam.comn4express.comknreddy.com
  2. 2.  Also called Stack Frames Activation records are entries on a call stack They maintain information about functions being called and their return locations They also contain parameters and local variables
  3. 3.  Contains an activation record for each function that is called Grows backwards (higher memory address to lower memory address) Has a stack pointer pointing to the top of the stack
  4. 4. void function2() { … Each function call function2(); adds an activation …} record to the call stack Stackvoid function1() { Pointer …} function2_1 function2int main() { … function1 function1(); …} main
  5. 5. Register Values Local VariablesCaller’s Frame/Base Pointer Return Address Parameters
  6. 6. int main(){} main
  7. 7. void func1(int a){int x;}int main(){func1(3); func1} main
  8. 8. void func1(int a){int x;} Register valuesint main() int x{ Frame ptr of main()func1(3); func1 Program counter of} main() main int a
  9. 9.  An activation record is created on the call stack when a function is called (winding). The activation record is removed from the call stack when the function returns (unwinding).  “Why can’t you return a pointer to a local variable declared within a function?”
  10. 10.  Recursive function calls will add an activation record to the stack for each call  “What is a stack overflow?”
  11. 11.  You can use pointers to access the activation record Example:  void func(int a) { printf(“Return address: %xn”, &a-1); }
  12. 12.  Email: k.nitin.r [at] gmail

×