Conditional: if | |||||||||||||
simple if statement | |||||||||||||
if ( i == j ) | $s1 | i | |||||||||||
i++ ; | $s2 | j | |||||||||||
j-- ; | |||||||||||||
in C: if condition is true, we "fall through" to execute the statement | |||||||||||||
if false, jump to next | |||||||||||||
in assembly, we jump if condition is true | |||||||||||||
need to negate the condition | |||||||||||||
assuming $s1 stores i and $s2 stores j: | |||||||||||||
bne $s1, $s2, L1 # branch if !( i == j ) | |||||||||||||
addi $s1, $s1, 1 # i++ | |||||||||||||
L1: addi $s2, $s2, -1 # j-- |