go to previous page   go to home page   go to next page hear noise highlighting

Answer:

No. Typically the caller has important information in some registers, and others (such as the stack pointer) are used for special purposes.


Register Use

To determine which registers sub can use, you could look at the code for main to see 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

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