Using MIPS: In the space below, replace the myadd subroutine with one named mygr
ID: 3686771 • Letter: U
Question
Using MIPS: In the space below, replace the myadd subroutine with one named mygray that will compute x=graycode(y);, which will return the gray code value of y. Basically, here you are implementing x=y^(y>>1).
####
#
# Addition routine:
#
# x = y + z
#
.text
.globl myadd
myadd:
la $t0, y # t0 = y
lw $t0, 0($t0)
la $t1, z # t1 = z
lw $t1, 0($t1)
addu $t2, $t0, $t1 # t2 = y + z
la $t0, x # x = t2
sw $t2, 0($t0)
jr $ra # return
Explanation / Answer
.text
.globl mygray
mygray:
la $t0, y # t0 = y
lw $t0, 0($t0)
slt $t1, $0, $t0 # t1 = 0 < t0
beq $t1, $t0, fi #if
fi:
la $t2, 0
lw $t3, $t0
li $v0, 0
loop:
bqt $t2, $t3, exit
addi $t2, $t2, 1
mul $t5, $t0, $t5 # t5 = y^y
add $v0,$t5
la $t5, x #x = y ^ y
j loop
jr $ra # return
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.