I'm writing a program in MIPS
, and I'm struggling with using the sw
function to write an answer to memory. Here's a sample code to help explain the issue:
.data
byteArray: .byte 0,1,0,1
finalResult: .word 0
.text
la $t0, byteArray
la $t1, finalResult
lb $t2, 0($t0)
add $t3, $t2, $zero
lb $t2, 1($t0)
add $t3, $t2, $t3
lb $t2, 2($t0)
add $t3, $t2, $t3
lb $t2, 3($t0)
add $t3, $t2, $t3
sw $t3, 0($t1)
In this program, I just want to count the number of bytes
in my array
that are equal to 1 (in this case the answer is 2), and store that result in memory in my answer to the variable finalResult
. When running the program, my result isn't being stored in the finalResult
variable.
I really appreciate any help in figuring this out! Thank you!