2012-11-15 28 views
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 

回答

1

你应该载入您的缓冲区的$a0和地址的缓冲区中$a1大小的系统调用之前阅读的字符串。

相关问题