0

ユーザーが指定した文字列の長さを計算しようとしています。コードを実行しようとするたびに、「PC = (特定のアドレス) で例外が発生しました」というメッセージが表示され、その後に次のメッセージが表示されます:「データ/スタック読み取りのアドレスが正しくありません: (別のアドレス)。スタックに関係があることはわかっていますが、問題がわかりません。MIPS のコードは bello で、QtSpim を使用しています。あなたの助けは非常に高く評価されます。

sentence:   .space 6
Prompt: .asciiz "Enter the sentence. Max 6 characters, plus a terminator  .\n"  

        .text       # Start of code section
main:               # The prompt is displayed.

    li $v0, 4        # system call code for printing string = 4
    la $a0, Prompt  # load address of string to be printed into $a0
    syscall         # call operating system to perform operation;
                    # $v0 specifies the system function called;
                    # syscall takes $v0 (and opt arguments)

##read the string, plus a terminator, into the sentence
    la      $t0,    sentence
    li      $t0,    6
    li      $v0,    8

    add $v0, $zero, $zero   #initialize length to zero
loop:
    lbu $s0, 0($t0)      #load one character of string
    addi $t0,$t0,1          #point to next character
    addi $v0,$v0,1          #increment length by 1
    bne $s0,$zero, loop     #repeat if not null yet
end_loop:
    addi $v0, $v0, -1       #don't count the null terminator

    li $v0, 4               #display the actual length
    syscall

exit: #exit the program 
    li $v0, 10
    syscall
4

1 に答える 1