Reputation: 83
I'm new to MIPS assembly, I'm trying to make a program that finds the character just before "?"
However, for example when I enter input like " abc?"
, output is "c?"
. I can't find my mistake.
code is here:
.data
buffer: .space 1024
.text
.globl main
main:
la $a0,buffer
li $v0,8
syscall
la $t1,buffer
loop:
lb $t2,($t1)
beq $t2,'?',loop1
add $t1,$t1,1
j loop
loop1:
sub $t1,$t1,1
move $a0,$t1
li $v0,4
syscall
li $v0,10
syscall
Upvotes: 1
Views: 9276
Reputation: 58447
You're using the print_string
syscall, which won't stop until it finds a NUL terminator.
If you only want to print a single character it would be better to use the print_character
syscall (11); i.e. replace
move $a0,$t1
li $v0,4
with
lb $a0,($t1)
li $v0,11
Upvotes: 2