assembly - MIPS - Branching convention with bne -
in lecture, our professor said there reason behind using bne
in branching rather using beq
(and left figure out), example shown below.
if ( == j ) i++ ; j-- ;
which compiles down to
bne $r1, $r2, l1 # branch if ! ( == j ) addi $r1, $r1, 1 # i++ l1: addi $r2, $r2, -1 # j--
also, in link, being implied convention in mips assembly implement conditional branching in negation manner. best bet was, keeping common case simple - , therefore fast-, because intuitively if checking equality expect more become equal, , therefore pc branch when not equal. think pushed hard make reasonable, still couldn't distinguish core difference between implementing in beq
or in bne
. appreciate if explains why.
consider code if had used beq
. might end this:
beq $r1, $r2, l1 l2: addi $r2, $r2, -1 # j-- ... ... l1: addi $r1, $r1, 1 #i++ j l2
or this:
beq $r1, $r2, l1 addi $r2, $r2, -1 # j-- j l2 l1: addi $r1, $r1, 1 #i++ addi $r2, $r2, -1 # j-- l2:
in either case you'd have branch in 1 of execution paths, compared if had used bne
@ beginning.
Comments
Post a Comment