user1902535
user1902535

Reputation: 155

What is wrong with my MIPS assembly program?

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

Answers (1)

Alexey Frunze
Alexey Frunze

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:

  1. 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?

  2. 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.

  3. 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

Related Questions