Must the nop follow the jal?
Yes. (Assuming a real MIPS chip with branch delays.) With QTSPIM branch delays can be turned off.
For the next example, the main program
asks the user for integers x and y
and writes out the maximum of x*x, x*y,
and 5*y.
Look ahead to page 22 to see main.
main uses this sub-task:
Write a subroutine that returns the maximum of
three expressions: x*x, x*y,
and 5*y
for integer arguments x and y.
The integers use two's complement representation.
Use stack-based linking.
With our stack-based linkage convention this is:
Subroutine maxExp
Input: $a0 -- x, a two's complement integer
$a1 -- y, a two's complement integer
Returns: $v0 -- the maximum of x*x, x*y, or 5*y
Can this program use the subroutine maxInt?