Я пытаюсь вычислить длину строки, заданной пользователем. Каждый раз, когда я пытаюсь запустить код, я получаю сообщение «Произошло исключение на ПК = (определенный адрес), за которым следует сообщение: «Неверный адрес в данных/чтении стека: (другой адрес). Я знаю, что это как-то связано со стеком, но я не могу понять проблему. Код в MIPS прекрасен, и я использую 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