2012-11-15 42 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大小的系統調用之前閱讀的字符串。

相關問題