Homework 2

  1. For the following program fragment (you can assume C syntax, pass by value parameters and static scoping), draw diagrams showing each stage in the life of the run-time stack from the start of execution until routine beta is called recursively by alpha (i.e. the top activation record should be for beta.) Show how the dynamic and static links are set at each stage, as well as values for all the variables and parameters.

int i = 1, j = 2, k = 3;
beta(int);

alpha() {
  int i = 4, m = 5;
  ...
  i += k + m;
  beta(i);
  ...
}

beta(int p) {
  int k = 6;
  ...
  i = j + k + p;
  alpha();
  ...
}

main() {
  ...
  beta(i);
  ...
}

 

Assignment due: Friday, March 23rd., in class.