mips程序,用于查找字符在特定字符串中出现的次数

时间:2013-12-04 21:16:02

标签: mips32

这是我的代码:

        .text
        .globl main
main:
        li $t0,0 #creats address
        la,$t1,str #creats addresses
        lb $t2,char #reads "c"
                lb $t3,($t1) #reads firs character from the string
if:     beqz $t3,exit #if $t3=0 go to exit
        bne $t3,$t2,next #if $t3!=$t2 go to next
        addi $t0,$t0,1 # adds 1 to $t0
next:           addi $t3,$t3,1 #puts next character in $t3
        j if
exit:
        li $v0,4
        la $a0,mess
        syscall
        li $v0,1
        move $a0,$t0
        syscall
        li $v0,4
        la $a0,CRLF
        syscall
        li $v0,10
        syscall
        .data
str:    .ascizz  "aaabbccccddabceeffeeghi"
char:   .ascii   "c"
mess:   .ascizz  "Count is"
CRLF:   .ascizz  "\n"

我收到此错误:

spim: (parser) syntax error on line 25 of file /Users/Geil/Desktop/poutsa.s
      str:  .ascizz  "aaabbccccddabceeffeeghi"

1 个答案:

答案 0 :(得分:1)

看起来您希望它是.asciiz,而不是.ascizz

.asciiz声明一个字符串为null终止。 .ascizz是语法错误。