In Appel Chapter 6, there is an illustration of a stack frame.
Here, the static link and local variables (which were omitted
at the lecture) are placed between the arguments and the return address.
One or both of these could in our architecture
may be more naturally be placed after the return address
instead of before.
With Appel Chapter 6 as a starting point, discuss the following points:
-
Where should the static link point when calling a local function
in ones own scope and a function further out, respectively.
Remember recursive functions in this connection.
-
When using a variable defined in a scope further out,
which code must the compiler generate in order to find
this variable and where does the compiler find the
necessary information to find out which code to generate?
-
What code must the compiler generate when a function is called
such that static link will be set up correctly for the called function
and how does the compiler find the necessary information to do this?