Written work 9
Due on November 15th @ 3:00 PM (in class, to Drew, or at Engineering front office)
Not accepted late
Question 1

In class, we have used the two registers (the base pointer and the stack pointer) to track the boundaries of an activation record. A mysterious cloaked figure claims to have implemented a Drewno Mars compiler that only needs to use the stack pointer. Is this possible for Drewno Mars? How about for other languages?

Question 2

Assume that your nemesis has invented a language with the following aspects:

  • Users may only define 10 functions
  • Dynamic memory is allowed, but is always placed on the heap
  • Functions may not call themselves
Your nemesis claims that you will never run out of memory on a function call, and has therefore designed a runtime environment in which programs only have 100 memory slots. Describe at least 2 scenarios in which a function call will cause you to run out of memory. You may write pseudocode if you wish.

Question 3

Consider the following 3AC snippet. What code is generated from each quad to create X64 code?
Q1: [b] := 1
Q2: ifz [b] goto Q4
Q3: [b] := 0
Q4: nop

Question 4
We have discussed two memory regions that "grow" and "shrink" dynamically: the heap and the stack. What is the difference between how these regions are used?