MIPS - 打印字符串会导致尝试打印数组值时出错

时间:2013-04-16 01:58:56

标签: assembly mips

没有任何字符串,这个程序运行正常。但是,当我添加代码块时,如果我把这个块拿出去,它会运行"我得到一个错误,它说"在这里导致错误"。我得到的错误是"运行时异常在0x00400028:地址超出范围0x00000002"

我不知道为什么我会收到此错误。我不知道如何打印字符串会在尝试从堆栈中打印int时出错。

我一直在努力解决这个问题几个小时,而且我还没有为MIPS找到很多帮助或资源,所以任何帮助都会受到高度赞赏并且非常有用。

.data 
.align 2
list:  .space 40    #an array of 10 ints
blank: .asciiz " "  
mess: .asciiz "The values in the array are "    


.globl main
.text

main:
    jal read

    li $v0, 4
    la $a0, mess
    syscall

    jal print
    jal total
    jal average
    lw $a0, 0($sp)  #load avererage from stack
    li $t0, 1   #print it
    syscall     #causes ERROR here                     ############
    b done      #end program

#reads in 10 digits into array      
read:
    li $v0, 5       #prompts for int
    syscall
    sw $v0, list($t0)   #stores int in array

    addi $t0, $t0, 4    #holds the number 4
    blt $t0, 40, read   #repeats until array is full
    jr $ra          #return to caller

#prints array   
print:
    lw $a0, list($t1)   #loads int from array
    li $v0, 1       #print int
    syscall

    li $v0, 4       #if I take this block out it runs      ########
    la $a0, blank       #
    syscall         #

    addi, $t1, $t1, 4   #counter 
    blt $t1, 40, print  #repeats until array it full
    jr $ra          #return to caller

#adds the total of all array elements 
total:
    lw $t3, list($t2)   #gets ints from array 
    add $s0, $s0, $t3   #adds number to running total
    addi $t2, $t2, 4    #counter 
    blt $t2, 40, total  #repeat until all ints are added
    addi $sp, $sp, -4   #allocate space on array
    sw $s0, 0($sp)      #store total on stack
    jr $ra          #return to caller

#divides the total by 10, for the average       
average:
    lw $a0, 0($sp)      #gets the total from the stack
    addi $t4, $t4, 10   #10 to divide by
    div $a0, $t4 
    mflo $t5
    sw $t5, 0($sp)      #store aveg in stack
    jr $ra      

done:

1 个答案:

答案 0 :(得分:1)

您忘记将$v0设置为1.我猜你设置$t0而不是$v0