0x004002b0处的运行时异常:地址超出范围0x10400000

时间:2016-11-10 17:58:27

标签: assembly mips mips32

我正在学习MIPS汇编语言,并且我遇到了部分程序错误“地址超出范围”的问题。有人可以帮助我。

错误行294:0x004002b0处的运行时异常:地址超出范围0x10400000

    .data
     fileName:      .space  8
     fileContents:      .space  50000
     legalWords:        .space  50000
     correctWords:      .space  50000   

    .text

   importFile:
    li   $v0, 13        # open file
    la   $a0, fileName  # load address with filename
    li   $a1, 0         #flags      
    li   $a2, 0         #mode 0: read, 1: write  
    syscall             # open a file (file descriptor returned in $v0)
    addi $sp, $sp, -4   #make room on the stack
    sw   $s6, 0($sp)    #save $s6 since we are using elsewhere
    move $s6, $v0       # save the file descriptor in $s6
    li   $v0, 14        # system call for read from file
    move $a0, $s6       # file descriptor 
    la   $a1, fileContents  # address to buffer to store read data
    li   $a2, 500000        # maximum number of characters to read
    syscall             # read from file
    li   $v0, 16        # system call for close file
    move $a0, $s6       # file descriptor to close
    syscall             # close file
    lw   $s6, 0($sp)    # restore $s6
    addi $sp, $sp, 4    #restore the stack
   .
   .
   .
   #Fills Word List Until and Asterix is Read
   #a new word is stored every 12 bytes.

    fillWordList:
   li $a1, 0 #positon in legalWords
   li $a2, 0 #currentWord position counter
   fillWordListStart:
    lb $t0, fileContents($a0) # load current char
    beq $t0, 42, fillWordListEnd # found end of legalWords '*' return
    beq $t0, 10, saveWord #new line char found, current word loaded, go  save
    sb  $t0, currentWord($a2) #save character to currentWord
    add $a2, $a2, 1 #move to next position in currentWord
    add $a0, $a0, 1 #move to next position in fileContents
    j fillWordListStart

        saveWord:
            addi $s1, $s1, 1
            mul $t2, $a1, 12 #$t2 contains the position in legalWords were we start storing the currentWord
            li $a2, 0 #reset current word position to 0
            li $t4, 32 #load a ' ' char into $t4 for resetting currentWord
                saveWordStart:
                    lb $t3, currentWord($a2) #load char at current position
                    beq $t3, 0, saveWordEnd #reached end of current word return
                    sb $t3, legalWords($t2)    #copy to legalWords at current position
                    sb $t4, currentWord($a2)
                    add $t2, $t2, 1
                    add $t3, $t3, 1
                    add $a2, $a2, 1
                    j saveWordStart
        saveWordEnd:
            li $a2, 0   #reset current word position to 0
            add $a1, $a1, 1 #move to next position in WordList
            add $a0, $a0, 1 #move to next position in fileContents
            j fillWordListStart
   fillWordListEnd:
    jr $ra

     #-------------------------------End Fill Word   List-----------------------------------------------#

findFirstWord:
lb $t0, fileContents($a0)
beq $t0, 10, findFirstWordReturn #branches on newline character
add $a0, $a0, 1
findFirstWordReturn:
add $a0, $a0, 1
move $v0, $a0   #return position of first word
jr $ra

findNineLetterWord:
beq $v0, 10, findNineLetterWordReturn #nine letter word found *start of  legalWords
j getLength

findNineLetterWordReturn:
add $a0, $a0, -11
move $v0, $a0
jr $ra

        #----------------------Gets Length of current word in fileContents--------------------------------------------# 
 getLength:
 li $a2, 0  #word length
    getLengthStart:
        lb $a1, fileContents($a0)
        beq $a1, 10, getLengthEnd #new line char found current word length is stored
        add $a0, $a0, 1 #move forward one position in file contents
        add $a2, $a2, 1 #add one to wordlength
        j getLengthStart
 getLengthEnd:
add $a0, $a0, 1
move $v0, $a2
j findNineLetterWord

0 个答案:

没有答案