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
4

1 回答 1

1

您应该在系统调用之前加载缓冲区的地址和缓冲区$a0的大小以读取字符串。$a1

于 2012-11-16T10:38:51.667 回答