go to previous page   go to home page   go to next page

Answer:

No. Some registers contain important information.

Register Use

To answer the question, you could look at the code for main to determine which registers contain information and so can not be altered. Do this every place in main that sub is called, because different registers are likely to be in use at different places. Now write sub using only those registers that are not in use before any call.

This is tedious and error prone. Worse, if you make a change to main , you now might have to re-code sub using different registers.

One of the goals in writing a subroutine is to create a module that is independent of the rest of the code. We have not achieved that, yet.

Another issue is how data is passed into and out of the subroutine. Often data is in registers, and the results are in registers. Which registers?

By software convention (not by hardware) registers have been assigned different roles:

QUESTION 8:

Is the following code fragment correct?

  add    $t0,$s5,$s3   # calculate an important sum in $t0
  jal    somesub       # call a subroutine
  nop                  # branch delay
  mul    $s4,$t0,$v1   # multiply the sum