CS480 Lab Exercises

Consider the following quad file:
 1  27   0   0   0   0   0   0
 2  22   0   1   0   0   0   0
 2  17   2   1   2   2   0   5
 2  26   0   0   0   0   3   1
 2  19   0   0   0   0   0   6
 2  26   0   1   0   0   3   1
 2  20   4   1   0   0   0   0
 2  25   0   1   0   0   0   0
 2  26   0   0   0   0   1   0
 2  23   0   0   0   0   0   0
 1  21   0   0   0   0   0   1
 1  28   0   0   0   0   0   0
3
0
5
4
Problem #1: Create a picture showing the runtime stack at its deepest level.

Problem #2: Individually reverse engineer the quadfile as best you can showing the C code that produces the quadfile.

Problem #3: Go into the lab in groups of three and discuss your reversed engineered solutions.

Problem #4: Run the quadfile through the interpreter checking your activation record creation.

Problem #5: Work through the following C/quadfile example. Make sure you understand what is going on.


/* Pointer testcase */

int c[5];
main ()
{
  int *a;
  int b[3];

  b[1] = 100;
  c[2] = 90;
  *a = c[2];
  output(b[1],*a);
}


 1  27   0   0   0   0   0   0
 1  26   1   3   0   0   1   2
 2  22   0  12   0   0   0   0
 2  26   3   3   0   0   3   2
 2   1   4   2   2   9   3   6
 2  26   2  10   0   0   4   6
 2   1   2   2   2  11   3   7
 2  26   2  12   0   0   4   7
 2   1   2   2   2  11   3   8
 2   9   4   8   0   0   3   9
 2  26   4   9   0   0   4   1
 2   1   4   2   2   9   3  10
 2   9   4  10   0   0   3  11
 2   9   4   1   0   0   3  12
 2  20   4  12   0   0   0   0
 2  20   4  11   0   0   0   0
 2  25   0   2   0   0   0   0
 2  26   0   0   0   0   1   0
 2  23   0   0   0   0   0   0
 1  21   0   0   0   0   0   2
 1  28   0   0   0   0   0   0
13
0
5
0
0
0
0
0
0
3
1
100
2
90



Problem #6: Can you see how arrays work?
/* Final SA2 Example */
int c[5];
main ()
{
  int *a;
  int b[3];
  c[2] = 1;
  b[c[2]] = 100;
  a = &b[1];
  output(c[2],*a);
}

1  27   0   0   0   0   0   0
1  26   1   3   0   0   1   2
2  22   0  13   0   0   0   0
2  26   3   3   0   0   3   2
2   1   2   2   2   9   3   6
2  26   2  10   0   0   4   6
2   1   2   2   2   9   3   7
2   9   4   7   0   0   3   8
2   1   4   2   4   8   3   9
2  26   2  11   0   0   4   9
2   1   4   2   2  10   3  10
2  26   4  10   0   0   3   1
2   1   2   2   2   9   3  11
2   9   4  11   0   0   3  12
2   9   4   1   0   0   3  13
2  20   4  13   0   0   0   0
2  20   4  12   0   0   0   0
2  25   0   2   0   0   0   0
2  26   0   0   0   0   1   0
2  23   0   0   0   0   0   0
1  21   0   0   0   0   0   2
1  28   0   0   0   0   0   0
12
0
5
0
0
0
0
0
0
3
2
1
100
Any questions?