Lecture 21 Objectives
At the end of today's class you should
KNOW:
- how function calls are implemented by passing parameters and state-saving
information on the runtime
stack
- why a stack is necessary for languages that support recursive subroutines
BE ABLE TO:
- draw the activation records of the calling function and the called
function, for a function call written in C
- trace through a recursive subroutine written in LC-3 assembly language,
and draw a picture of the stack contents at different points in the execution
of the subroutine
Sample Exam Question:
(Problem 14.10 from the text) A C program containing the function
food has been compiled into LC-3 assembly language. The partial
translation of the function into assembly language is:
food ADD R6, R6, #-2
STR R7, R6, #0
ADD R6, R6, #-1
STR R5, R6, #0
ADD R5, R6, #-1
ADD R6, R6, #-4
...
- a). How many local variables does function food have?
- b). Say the function takes two integer parameters, x and
y. Generate the LC-3 assembly language code to evaluate the expression x + y.