In lecture, our professor said that there is a reason behind using bne
in branching rather than using beq
(and left us to figure it out), like the example shown below.
if ( i == j )
i++ ;
j-- ;
which compiles down to
bne $r1, $r2, L1 # branch if ! ( i == j )
addi $r1, $r1, 1 # i++
L1: addi $r2, $r2, -1 # j--
Also, in this link, it is also being implied that it is a convention in MIPS assembly to implement conditional branching in negation manner. My best bet was, it was for keeping the common case simple - and therefore fast-, because intuitively if we were checking for equality then we would expect it to be more likely to become equal, and therefore PC to branch when it is not equal. I think I just pushed hard to make it reasonable, but I still couldn't distinguish the core difference between implementing it in beq
or in bne
. I would really appreciate if someone explains why.