mipsqtspim

Memory address out of bounds error in MIPS but works in a different function


I am making a program in MIPS that will compare two strings but I can't seem to access the proper locations. I have a function that calculates the lenght of the strings which works fine, but when I try to use a different function (in this case its just a test to see if it works), it says that i'm acessing the wrong memory. I am using QTSpim to test it. The function that works is the duzinaStringa, the one that does not is the krajStringa. Currently it's just trying to print out the first character of the string so I can make sure it works

.text


krajStringa: 

li $v0,0
li $t0,0 #brojac1 
 
move $t2, $a0 #adresa prvog
move $t3, $a1 #adresa drugog

lb $a0,0($t2) 
li $v0,4 
syscall
jr $ra 






duzinaStringa:  
move $t1,$a0 
li $t0,0 
petlja: 
    lb $t2,0($t1) 
    beqz $t2,krajDuzine
        addi $t1,$t1,1
        addi $t0,$t0,1 
        j petlja

    krajDuzine: 
    addi $t0,$t0,-1 
    move $v0,$t0
    jr $ra


main:

la $a0,str1
li $v0, 4
syscall

la $a0, arr
li $a1,200 
li $v0, 8
syscall

la $a0,str1
li $v0, 4
syscall

la $a0, arr2
li $a1,200 
li $v0, 8
syscall

la $a0,arr
jal duzinaStringa
move $a2,$v0


la $a0,arr2
jal duzinaStringa
move $a3,$v0 

la $a0,arr
la $a1,arr2
jal krajStringa


li $v0,10
syscall

.data
arr: .space 200
arr2: .space 200
str1: .asciiz "Unesi string: \n"

Solution

  • As @ErikEidt pointed out, I used the wrong system call when printing the first character of a string.