I need to know how can I test the equality of two registers in MIPS without using branches? I need to make a new instruction that does the same as the beq without using branches... The Labeling part can be done easily by using the Jump instruction, but how can we check for equality ? Thanks in advance
0
votes
3 Answers
4
votes
If you've got two numbers X and Y, and X - Y equals 0, then X and Y are equal.
So, for example, if the two values you want to compare are in $t0 and $t1:
# $t2 will be 0 if $t0 and $t1 are equal, and non-zero otherwise
subu $t2, $t0, $t1
If you want to normalize the result to either 0 (non-equal) or 1 (equal), you could expand the above with:
# Set $t2 to 1 if it's non-zero
sltu $t2, $zero, $t2
# Flip the lsb so that 0 becomes 1, and 1 becomes 0
xori $t2, $t2, 1
0
votes
0
votes