2015-04-22 146 views
1

我遇到了我的代碼有問題。我目前正在收到第28行的運行時錯誤:運行時異常在0x00400044:地址超出範圍0x00000001。運行時錯誤(輸入時崩潰)在MIPS(使用MARS)

程序應該輸入並以降序返回。

main: 
    move $s0,$gp   #get the intial point to 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 to put the string 
    la $a0,msg1  # 
    syscall  # 
    add $s1,$s0,$zero # copy the pointer to array in $s1 
    entervalues: 
    li $v0,5  # get the value in v0 
    syscall  # 
    beq $v0,$t7,bubblesort # end of string run to bubblesort 
    lb $v0,0($s1) # **HERE IS THE ERROR** 
    addi $s1,$0,1  # move the $s1 pointer by one 
    add $t5,$s1,$zero # $t5 stores the 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 to put the string 
    la $a0,msg5  # 
    syscall  # 
    li $v0,4  # system call to put the string 
    la $a0,msg4  # 
    syscall  # 
    li $v0,4  # system call to put the 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 to put the string 
    la $a0,msg6  # 
    syscall  # 
    li $v0,5 

任何幫助將不勝感激!

回答

1

你的問題似乎是在指示:

addi $s1,$0,1  # move the $s1 pointer by one 

這不你的評論的狀態。它只是立即在$s1中加入1。 addi添加第二個和第三個參數並將其添加到第一個參數中。

您應該發出:

addi $s1,$s1,1  # move the $s1 pointer by one 

你做同樣的事情在你的代碼。例如,當你發出

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

你可能意味着

addi $t6,$t6,1 #s1-1 -> s0 
相關問題