Runtime error (crashes on input) in MIPS (using MARS) -


i having trouble code. getting runtime error on line 28: runtime exception @ 0x00400044: address out of range 0x00000001.

the program supposed take input , return in descending order.

main:      move $s0,$gp           #get intial point save array       addi $t0,$0,1          # $t0 = 1      add $t1,$zero,$zero        #       add $t2,$zero,$zero        #       add $t3,$zero,$zero        #       add $t6,$zero,$zero              add $t4,$zero,$zero              sub $t7,$zero,1            # terminate              li $v0,4       # system call put string      la $a0,msg1        #       syscall        #      add $s1,$s0,$zero  # copy pointer array in $s1      entervalues:      li $v0,5       # value in v0       syscall        #       beq $v0,$t7,bubblesort # end of string run bubblesort      lb $v0,0($s1)  # **here error**      addi $s1,$0,1      # move $s1 pointer 1      add $t5,$s1,$zero # $t5 stores end value      j entervalues bubblesort:      add $t4,$s0,$zero      addi $t6,$0,1    #s1-1 -> s0      sub $s1,$s1,$t0      beq $s1,$s0,ending       add $s2,$s0,$zero loopinterno:      lb $t1,0($s2)      # first element      lb $t2,1($s2)      # second element      slt $t3,$t2,$t1        #       beq $t3,$zero,proximo  #       sb $t2,0($s2)      #       sb $t1,1($s2)      #        proximo:      addi $s2,$0,1      #      bne $s2,$s1,loopinterno #      li $v0,4       # system call put string      la $a0,msg5        #       syscall        #      li $v0,4       # system call put string      la $a0,msg4        #       syscall        #      li $v0,4       # system call put string      la $a0,msg5        #       syscall        # imprime:      li $v0,1      lb $a0,0($t4)      syscall      li $v0,4      la $a0,msg2      syscall              addi $t4,$0,1      bne $t4,$t5,imprime      jal bubblesort  ending:      li $v0,4       # system call put string      la $a0,msg6        #       syscall        #      li $v0,5 

any appreciated!

your problem seems in instruction:

 addi $s1,$0,1      # move $s1 pointer 1 

which not comment states. puts immediate 1 in $s1. addi adds second , third argument , puts addition in first argument.

you should have issued:

 addi $s1,$s1,1      # move $s1 pointer 1 

you same thing on code. example when issue

 addi $t6,$0,1    #s1-1 -> s0   

you probable meant

 addi $t6,$t6,1    #s1-1 -> s0   

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -