2. (7 pts) Translate the following block of C code to MIPS assembly: if (i > 10) MemArray[i] = 0; else MemArray[i] = - MemArray[i]; Assume that the variable i is bound to register $t0, and that the base address of array MemArray is in register $s0.
ANSWER :
GIVEN
CODE:
li $t1, 10
sll $t2, $t0, 2
#offset for i
add $t3, $s0, $t2 #address of
MemArray[i]
bgt $t0,$t1,IF_CON #condition
ELSE:
#else body
lw $t4,0($t3)
sub $t4, $0, $t4 #changing sign
sw $t4,0($t3)
j NEXT
IF_CON:
#if body
li $t4,0
sw $t4,0($t3) #storing
zero
NEXT:
Get Answers For Free
Most questions answered within 1 hours.