1
문자열의 문자 수를 계산하는 간단한 프로그램을 작성하려고합니다. 그것은 구조를 따르는 것 같은데, 나는 여전히 나쁜 주소 오류가 계속 나왔다.계속 나쁜 주소 예외가 계속 발생합니다. 그 이유는 무엇입니까?
.data
array: .space 100
prompt1: .asciiz " Enter the string that you would like to reverse and calculate character: "
prompt2: .asciiz " "
.text
main:
la $a1, array # allocate the array space
ask:
li $v0, 4 # print String
la $a0, prompt1 # load prompt1
syscall
li $v0, 8 # read the string
syscall
move $a1, $v0 # move input to $a1
li $t0 ,0 # $t0 will hold the actual numbers of character in the string
loopCount:
lbu $t1, 0($a1) # load the next character into t1
beqz $t1, print # check for the null character
addi $a1, $a1, 1 # increment the string pointer
addi $t0, $t0, 1 # increment the count
b loopCount # return to the top of the loop
print:
li $v0, 1
move $a0, $t0
syscall