fosho
fosho

Reputation: 1676

MIPS if statement not being entered

I am trying to see if the input a user entered is 0 for the second character, for example if they enter "A0123" then the statement is true. I have managed to remove the equals sign, however when I run my program, it does not enter into the branch that is supposed to check that the 2nd character is 0.

In the register $t2 I store the users exact input (with newline character). and in $s5 I store the asciiz string "0" with a newline as well. Then I remove the first character of the user's input.

What is going wrong and how can I fix it?

.data

zero: .asciiz "0\n"


la $s5, zero

addiu $t2,$t2,1     #remove equals sign
beq $t2, $s5, zero2      #referencing 0
beq $t2, $s6, one2
j exit2
zero2:
    move $t2, $t0
    j exit2

Upvotes: 0

Views: 311

Answers (1)

Jester
Jester

Reputation: 58762

$s5 and presumably $t2 are pointers and they will never be equal. You should compare the characters they point to. You can do something like:

la $s5, zero
lb $s5, ($s5)
lb $t3, 1($t2)
beq $t3, $s5, zero2

Of course you don't really need the zero string, you can simply use an immediate, such as:

lb $t3, 1($t2)
li $s5, '0'
beq $t3, $s5, zero2

Upvotes: 1

Related Questions