please help!! In the space below, write MIPS code for a leaf subroutine mymul th
ID: 3801879 • Letter: P
Question
please help!!
In the space below, write MIPS code for a leaf subroutine mymul that will compute x = y*z;. Although there are many ways to do a multiply, here's C code for one of them that you might want to use: extern int x, y, z; void my mul(void) {/* do x = y * z the hard way... */int t0 = 0; int t1 = 1; int t2 = y; int t3 = z; while (t1 ! = 0) {if (t1 & t3) ! 0) {t0 += t2;} t1 += t1; t2 += t2;} x = t0;} #### # # Multiplication routine: # # x = y * z # .text .globl mymul mymul: # # Your code here # jr $ra #returnExplanation / Answer
mymul:
move $t0,0 # t0 = 0
move $t1,1 # t1 = 1
lw $t2,y # t2 = y
lw $t3,z # t3 = z
while: # while loop
beq $t1,0,end # break While condition ( t1 != 0)
and $t6,$t1,$t3 # t6 = t1 & t3
bne $t6,$0,if # if t6 != 0
next:
add $t1,$t1,$t1 # t1 += t1
add $t2,$t2,$t2 # t2 += t2
if:
add $t0,$t0,$t2
j next
end:
sw $t0,x # x = t0
jr $ra
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.