简体   繁体   中英

Find number of spaces in a string mips assembly

So I have a string in .data. The string is "e8 erercergrrrg,". I want to find the number of spaces in the string. It is stored in $a0, but in a different file and both the file I am writing the method for finding spaces and the file with the string is linked using the "include" feature.

My code isn't working even though I think the idea is right.

my code so far

lb $s1, ($a0)
la $s2 ' ' 
li $v0, 0

findNumSpaces:
beq $s1, $zero, printNumSpaces
beq $s1, $s2, isSpace
addi $a0, $a0, 1
lb $s1, ($a0)
j findNumSpaces


isSpace:
addi $v0, $v0, 1
addi $a0, $a0, 1
lb $s1, ($a0)
j findNumSpaces

printNumSpaces:
li $v0, 1
syscall
  1. When it finds a space, it doesn't increment $a0 or load the new value of $s1.
  2. It doesn't check for the end of the string, so it will loop forever.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM