how would I find a particular character in a user inputed string that has a known length in MIPS? I've looked on SO as well as many other websites however, none can seem to fundamentally explain how to manipulate user inputed data.
Here's what I have so far:
A_string:
.space 11
buffer:
asciiz"Is this inputed string 10 chars long?"
main:
la $a0, buffer
li $v0, 4
syscall
li $v0, 8
la $a0, A_string
li $a1, 11
syscall
You would have to iterate over the read buffer looking for the specific character you want.
For example, suppose you want to find character 'x'
in the input data, and assuming this snippet is put after your code so $a1
already has the maximum number of characters read. You would have to start from the beginning of the buffer and iterate until either the character you expect is found or you have traversed the entire buffer:
xor $a0, $a0, $a0
search:
lbu $a2, A_string($a0)
beq $a2, 'x', found # We are looking for character 'x'
addiu $a0, $a0, 1
bne $a0, $a1, search
not_found:
# Code here is executed if the character is not found
b done
found:
# Code here is executed if the character is found
done: