Section 9.5
Review Questions

Subroutines

  1. What are some reasons why subprograms are used? (Use your general knowledge about computer programming to answer this one.)
answer...
  1. to reuse code
  2. to shorten the total program in memory
  3. to prevent mistakes from copying the same code
  4. to make the program more modular and more easily fixed
  5. to make the program more modular, hence easier to understand
  1. What are some synonyms for subprogram? List at least 3.
answer...
function, subroutine, procedure
  1. Which name is used by FORTRAN and most assembler languages?
answer...
subroutine
  1. Where does the CSC-1 save the return address?
answer...
in the S register
  1. What two CSC-1 instructions implement subprograms?
answer...
CAL and RET
  1. Where does the CSC-1 store parameters?
answer...
in memory
  1. 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
  1. What is the most popular way of implementing subprograms and parameters?
answer...
using a stack
  1. What is another name for activation record?
answer...
frame
  1. What two registers would be needed if the CSC-1 used a stack?
answer...
SP and FP
  1. Does the actual subprogram code begin with a special instruction?
answer...
No
  1. What role do labels play in assembler subprograms?
answer...
they are targets of jumps or names of variables
  1. 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