Reputation: 155
I'm trying to create a program that loops through an array to reach the final value of 0.
While going through each element in the array, I need to increment the value by 2 and store the final result in $v0. (I have no idea how to do this)
Here is my code so far:
.data
list: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 0
.text
li $s0, 0x10010000
increment:
beq $s0, $zero, EndLoop
lw $s1, 0($s2)
sw $s1, 0($s2)
la $s2, list
la $s1, list
lb $s2, 0($s1)
addi $s2, $s2, 2
sb $s2, 0($s1)
addi $s1, $s1, 1
j increment
EndLoop:
My questions are:
I Keep getting an error saying runtime exception, address out of range. Any idea why?
Could anyone point me in the right direction about storing the final values in $v0?
Upvotes: 0
Views: 574
Reputation: 62048
I Keep getting an error saying runtime exception, address out of range. Any idea why?
Sure, here:
.text
li $s0, 0x10010000
increment:
beq $s0, $zero, EndLoop
lw $s1, 0($s2)
Problems:
You don't seem to define where your program is supposed to start its execution. I'd expect some label at the beginning of the code, but I'm seeing nothing. Is the relevant part simply not shown in the question?
Your code is attempting to read from a memory location whose address is contained in register s2
, however your code does not initialize this register.
Also, you never modify s0
, so the loop is hopelessly endless.
Could anyone point me in the right direction about storing the final values in $v0?
I see no problem with storing anything in v0
.
Upvotes: 1