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

Answer:

No. As many variables as needed may be pushed onto the stack (in step 4.)

This results in the rule that a subroutine (in a language like C or Java) can have as many local variables as needed.


Rules for Main

main is started by QTSPIM and returns control to QTSPIM. Because of this, it needs different rules.


main's Prolog ( done at the start of main):

  1. QTSPIM has set up the stack pointer register $sp.
  2. Initialize the frame pointer: $fp = $sp - space_for_variables. The space for variables is four times the number of local variables.
  3. Adjust the stack pointer: $sp = $fp.
main's Body:

  1. main may use any register
  2. main refers to local variables as disp($fp).
  3. main may push and pop values on the stack using $sp.

Calling a Subroutine (as done by main):

  1. Push any registers $t0-$t9 that contain values that must be saved.
  2. Put argument values into $a0-$a3.
  3. Call the subroutine using jal.

Regaining Control from a Subroutine (as done by main):

  1. Pop any registers $t0-$t9 that main pushed in step 7.

main's Epilog (done at the end of main):

  1. Load $s0 with 10.
  2. Return to QTSPIM using syscall.

QUESTION 8:

Could main just not bother to use T registers?


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