11/22/04
A student writes:
professor patt i was wondering if you could help me in undrestanding the whole thing about frame ptrs and activation records (what are they any way ) i mean whats the use of having them thank you for your time << name withheld for the one who is confused >>(good enough i think)
Figuring that the rest of you are preoccupied with the
fourth program, I respond privately and without even commenting on the
name he provided for himself):
He is persistent, and comes back with: Where is this question coming from. Frame pointers are in the
second half of the book.
I am happy to talk to you about it. I just don't understand
why you are concerned about it right now.
Yale Patt
professor patt i was reading ahead and thanks for responding to my mail and i do hope you dont mind answering my mail even though it is in the second half of the book
So, by now, you know me. Someone wants to learn, I am
happy and ready to teach. But now the rest of you are all through (for
better or worse) with the fourth program, so I may as well let you in on
the answer. AGAIN, this is beyond the scope of 306, so feel free to
delete and move on.
For those who want to know now:
If you have programmed in some high level language, you know about functions
or subroutines. Some languages call them by one name, other languages call
them by the other name. And, still others use both names with fine distinctions
as to which should be used in a particular situation. Both are fine here.
The idea is that in the middle of your high level language program, you wish
to execute some function, like in
you need to execute three functions: SQR twice, and then after that,
SQARE_ROOT once.
Each function (or subroutine) consists of a section of your program which
performs its task, which in turn is needed by something else in the program.
In this example, each result of SQR is one of the two source operands for +,
whose result is in turn the source operand of SQUARE_ROOT.
The compiler's job is to generate the machine language program (we will talk
in terms of assembly language rather than 0s and 1s to make the explanation
easier to read) to do the job. In the object code, the subroutine that
computes SQR(a) starts at location SQR and ends with a RET instruction
(implemented by JMP using R7, as you know). At runtime, a JSR(R) provided
by the compiler will load PC with the address SQR and process until the RET
returns control back to that part of the program that called SQR. Each time
SQR is called, it needs to be provided with the source operands for that
function/subroutine, and each time RET is executed, the result must be
provided to the part of the program that called it.
How does the computer manage the various information it is passing back and
forth between the calling program and the called function/subroutine? That
is, where are the source operands put. What about the result it sends back.
What about the return linkage. In our work in 306, we are using the registers
for all this information. That is fine, provided we have enough registers.
The activation record (often called a stack frame) is a convenient mechanism
for handling all of this. That is, the compiler, in response to a function
call in the high level language, generates a block of memory called a run-time
activation record. Each location in the block of memory has a designated
purpose: a location for each of the specified source operands (arguments,
they are called), a location for each of the results that the function is
to produce, and a location for the return linkage. Before the function is
called, the calling program stores the source operands to the source operand
locations of the activation record. During the execution of the function,
the function loads those values from those locations in order to do its job.
After the function finishes its computation, it stores the results it
generated into the result operand locations of the activation record. After
the RET, the calling program loads the results as needed from the results
operand locations of the activation record.
In 30 words or fewer: The run-time activation record is a block of memory
used for communicating necessary information between the part of the program
that calls the function and the function itself.
Have fun in 312.
But FIRST, we got 306 to get past. Good luck with that.
Yale Patt c = SQUARE_ROOT(SQR(a) + SQR(b)),