Topic 3 · Class activity 3 · Week 7 · Wednesday

Draw the Activation Record

Predict the frame, compare it with Dragon's general form, check it against the generated assembly, then sabotage the epilogue.

Format pairsTime 50 min

The point

Draw the activation record you expect, then hold the generated assembly against it. This is the activity that makes function calls stop being magic.

Do this

  1. Draw the frame you expect for
    int addUp(int a, int b) {
        int t;
        t = a + b;
        return t;
    }
    Label every slot with its offset and give the total size. Compare your drawing against the general activation record in the notes: which of Dragon's fields does yours have, and which does it omit? For each omission, say why this language does not need it.
  2. Compile it without -q, find the reported frame size and symbol table, and reconcile.
  3. Read the prologue and epilogue and account for every instruction. There should be no line you cannot explain.
  4. Sabotage the epilogue. Comment out the lw $ra restore. Predict where control goes, then run it.
  5. Sabotage differently. Restore that, and make return fall through instead of jumping to the epilogue. Test with a function having a return in the middle. Explain the result.
  6. Draw the stack at maximum depth for fact(3). How many frames? What is in each $ra slot? Confirm against the activation tree idea from the notes.

Deliverable

Your predicted frame beside the compiler's, with the omitted-field analysis; an annotated prologue and epilogue; a paragraph for each sabotage; and the fact(3) stack diagram.