Section 9.5
Review Questions
Subroutines
-
What are some reasons why subprograms are used?
(Use your general knowledge about computer programming to answer this one.)
answer...
- to reuse code
- to shorten the total program in memory
- to prevent mistakes from copying the same code
- to make the program more modular and more easily fixed
- to make the program more modular, hence easier to understand
-
What are some synonyms for subprogram? List at least 3.
answer...
function, subroutine, procedure
-
Which name is used by FORTRAN and most assembler languages?
answer...
subroutine
-
Where does the CSC-1 save the return address?
answer...
in the S register
-
What two CSC-1 instructions implement subprograms?
answer...
CAL and RET
-
Where does the CSC-1 store parameters?
answer...
in memory
-
Which parameter calling method is used by the CSC-1?
call by name
call by reference
call by value
call by value/result
answer...
call by value/result
-
What is the most popular way of implementing subprograms and parameters?
answer...
using a stack
-
What is another name for activation record?
answer...
frame
-
What two registers would be needed if the CSC-1 used a stack?
answer...
SP and FP
-
Does the actual subprogram code begin with a special instruction?
answer...
No
-
What role do labels play in assembler subprograms?
answer...
they are targets of jumps or names of variables
-
Suppose there is a subprogram called max which computes the
maximum of two parameters, called PARM1 and PARM2.
The call is max(a,b).
Write the CSC-1 instructions which would set up the paramters and
call the subprogram. Do not worry about the return value.
answer...
LOD A
STD PARM1
LOD B
STD PARM2
CAL MAX