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

Answer:

The subroutine starts with a prolog.

Subroutine Prolog (done by the subroutine at its beginning)

  1. Push $ra onto the stack.
  2. Push onto the stack any registers $s0-$s7 that this subroutine might alter.

Subroutine Body

  1. The subroutine may alter any T or A register, or any S register that it saved in the prolog (step 4).
  2. If the subroutine calls another subroutine, then it does so by following these rules.

Prolog

The subroutine prolog must push the return address.

If the subroutine uses an S it must push it. But this subroutine can be written without S registers.

The body computes the maximum of the two arguments and puts it in $v0.

## maxInt -- compute the maximum of two integer arguments
##
## Input:
## $a0 -- a signed integer
## $a1 -- a signed integer
##
## Returns:
## $v0 -- maximum

         .text
         .globl maxInt

maxInt:
          # save return address
          sub    $sp,$sp,4    # push $ra
          sw     $ra,($sp)

          # body
          move   $v0,$a0          # max = $a0
          bgt    $a0,$a1,endif    # if $a1 > $a0  
          nop
          move   $v0,$a1          #    max = $a1
endif:                            # endif 
          # epilog
           
 

QUESTION 13:

According to the rules of Stack-based Linkage ConventionStack-based Linkage, what should the epilog of this subroutine do?


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