Question
comment the code
a) Write a code that performs Z X Y. You need to call a subroutine called TIMES that computes Z Use registers to pass X and Y. Make sure that part a) works before you move to b) b) Add another subroutine called SQUARE that takes the value in A and square it, that is, it finds A A. SQUARE must use TIMES i. Test your program by computing the square of 12, for example. c) Now add another subroutine called FOUR that computes A*A*A A. This subroutine should call SQUARE twice. i. Test your program by computing 34. You should get the same result as 9 Note: do not use the multiplication instruction.
Explanation / Answer
TIMES:
=========
li $a0 a
li $a1 b
jal TIMES
add $t1 $0 $v0
syscall
SQUARE:
li $a3 a
add $a4 $0 $a3
jal TIMES
add $t2 $0 $v0
jr $ra
FOUR:
jal SQUARE
add $t3 $0 $v0
move $t3 $a5
jal SQUARE
add $t4 $0 $v1
move $t3 $a6
jal TIMES
add $t5 $0 $v0
syscall