The return value (the maximum) is already in $v0
.
So all the epilog needs to do is return to the caller.
It is OK if the return value is already in $v0
when the
epilog is reached.
Here is the complete subroutine:
## maxInt -- compute the maximum of two integer arguments ## ## Input: ## $a0 -- a signed integer ## $a1 -- a signed integer ## ## Returns: ## $v0 -- maximum .text .globl maxInt maxInt: # body move $v0,$a0 # max = $a0 bgt $a0,$a1,endif # if $a1 > $a0 nop move $v0,$a1 # max = $a1 endif: # endif # epilog jr $ra # return to caller nop
This subroutine could be put in
its own file, perhaps maxInt.asm
, and separately
assembled.
Later on it could be used with programs we don't
even know about, as long as they follow the
Stack-based Linkage Convention.
With QtSPIM, main and each subroutine can be placed in a separate file and separately loaded. Use the "File" menu. Use the "Reinitialize and Load File" menu choice for main, and use "Load File" with the subroutines.
Must the nop
follow the jr
?