MIPS [地址错误]-比较Switch指令中字符串的字符

时间:2019-03-17 13:55:52

标签: string assembly switch-statement mips qtspim

我的程序将从.txt文件中读取最多5个字符的数组,从'A'到'E'。

程序读取完数组后,有一个while循环会在达到5个char限制时停止循环,以及一个switch指令,如果已分析的char是5个之一从'A'到'E'的字母,程序将转到特定标签(例如algoA)。

当我尝试“扫描” bufferKey QtSpim时出现错误:

  Exception 4  [Address error in inst/data fetch]  occurred and ignored

我试图了解问题出在哪里,但我不明白。

这是代码:

.data
    fnf:        .asciiz "The file was not found!"
    donemsg:    .asciiz "Encoding complete!"
    key:        .asciiz "chiave.txt"
    bufferKey:  .space  5

.text
.globl main

main:

# Open KEY File
openKey:
    li     $v0, 13 
    la     $a0, key
    li     $a1, 0
    li     $a2, 0
    syscall
    move   $t7, $v0
    blt    $v0, 0, err

# Read KEY File
readKey:
    li      $v0, 14
    move    $a0, $t7    
    la      $a1, bufferKey
    li      $a2, 5
    syscall


decodeKey:

    li      $s3, 0          # i = 0 
    la      $s6, bufferKey  # $s6 is the Buffer
    addi    $s5, $v0, 1

loop:   ### WHILE ###
    add     $t1, $s3, $s3
    add     $t1, $t1, $t1
    add     $t1, $t1, $s6
    lw      $t0, 0($t1)

    ### SWITCH ###

    ## CASE DEFAULT ##
    blt     $t0, 0x41, done
    bgt     $t0, 0x45, done

    ## CASE A #
    beq     $t0, 0x41, algoA
    ## CASE B ##
    beq     $t0, 0x42, algoB
    ## CASE C ##
    beq     $t0, 0x43, algoC
    ## CASE D ##
    beq     $t0, 0x44, algoD
    ## CASE E ##
    beq     $t0, 0x45, algoE

    ## End of cycle ##
    add     $s3, $s3, 1
    beq     $s3, $s5, done
    j   loop


# Error
err:
    li      $v0, 4
    la      $a0, fnf
    syscall 

# Done
done:
    li      $v0, 10
    syscall

# Algo A
algoA:
    li      $v0, 4
    la      $a0, 0x41
    syscall         
    j   loop

# Algo B
algoB:
    li      $v0, 4
    la      $a0, 0($t1)
    syscall         
    j   loop

# Algo C
algoC:  
    li      $v0, 4
    la      $a0, 0($t1)
    syscall         
    j   loop

# Algo D
algoD:
    li      $v0, 4
    la      $a0, 0($t1)
    syscall         
    j   loop

# Algo E
algoE:
    li      $v0, 4
    la      $a0, 0($t1)
    syscall         
    j   loop

QtSpim发现错误的行位于指令中的loop

lw $t0, 0($t1)

0 个答案:

没有答案