In: Computer Science
Write a MIPS program that always checks the bit 0 of a memory data at address 0x0BF81234. If it is equal to one add nth and (n+1)th elements of an array and store it to memory address 0x0BF85678 . Suppose $t0 contains the address of the 0th element of an array of 32-bit data and $t1 = n.
Greetings!!
Code:
li $s0,0x0BF81234 #address given
lw $t0,0($s0) #load word from the given address
andi $t2,$t0,0x00000001 #check whether the LSB is 1
bne $t2,1,done #if the LSB is 0, goto label done
mul $t1,$t1,4 #if the LSB is 1, calculate the offset of nth element
add $s0,$s0,$t1 #calculate the address of the nth element
lw $t3,0($s0) #read the nth element
lw $t4,4($s0) #read the n+1 th element
add $t3,$t3,$t4 #add nth and n+1 th elements
li $s0,0x0BF85678 #load the given destination address
sw $t3,0($s0) #store the sum to the given address
done:
addi $v0,$0,10 #termination
syscall
Hope this helps