6.100%. TI PS/SP 5/S ogram includes a subroutine called myadd that performs x-(y
ID: 3606076 • Letter: 6
Question
6.100%. TI PS/SP 5/S ogram includes a subroutine called myadd that performs x-(y+z);. In the space below, replace - the myadd subroutine with one named isodd that will make x have the value 1 if y has an odd value and 0 if it is even. You should test your routine using SPIM before you submit it, which will require merging it with a test framework like the one used in this MIPS/SPIM program -- but only submit the myand routine here. Remember that you can and should comment vour code, especially if there are any known bugs. Half off for documented bugs. :-) # Addition routine: #x=y+z .text globl myadd myadd: la $te, y $t1, z $t1, «($t1) #t1 = z la $t0, $t2, X SW 0($t0) jr Sra # returnExplanation / Answer
Please find the MIPS code below with detailed comments:
.text
.globl isodd
isodd:
la $t0,y
lw $t0, 0($t0) t0 = y
and $t1, $t0, $1 # t2 will have logical AND of $t0 & 1
beq $t1,$1,$L1 # Branch to L1 if t2 = 1 ie y is odd
la $t2,x # y is even, so store x=0
sw $0, 0($t2)
j $L2
L1:
la $t2,x # y is odd, so store x=1
sw $1, 0($t2)
L2:
jr $ra #return
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.