user1738539
user1738539

Reputation: 941

MIPS Infinite loop/error with loading char byte

I'm trying to have the user enter either 'Y' to restart the program (branch back to main) or 'N' (branch to end program). I'm reading a single char using syscall opcode 12

endCheck:
la $a0, newLine             # Print the newLine
li $v0, 4
syscall

la $a0, endPrompt           # print the Start over message
li $v0, 4
syscall

li $v0, 12              # take in char input
syscall
move $t0, $v0

lb $t1, ($t0)               # Load the char byte into t1

beq $t1, 89, main           # Go back to start if they entered 'Y'
bne $t1, 78, endCheck           # Ask the user again because input was not 'N' or 'Y'

li $v0, 10              
syscall

I'm getting an error on the lb line. And even when I allocated space of 1 byte on the data segment and read the input as a String of 1 character, I get an infinite loop (it's always branching back to endCheck when it does compile right) What am I doing wrong?

Upvotes: 0

Views: 687

Answers (2)

Ken Harvey
Ken Harvey

Reputation: 33

This might be of use to anyone seeing this old post; syscall 12 goes into this infinite loop using spim, but behaves properly using qtspim. spim hasn't been in development since 2010, but I was making some use of it, as it had emacs integration.

Upvotes: 1

Jeff
Jeff

Reputation: 7684

When you use syscall 12, the character itself is returned in $v0. It doesn't give you an address from which to read the character. You can omit the lb entirely.

Consequently, you're using $t1 for the comparisons when you should be using $t0.

Upvotes: 1

Related Questions