|
|
|
|
|
|
|
|
|
|
|
|
|
|
Conditional: if-else |
|
|
|
|
|
|
|
|
if-else |
|
|
|
if ( i == j ) |
|
$s1 |
i |
|
|
|
|
|
i++ ; |
|
$s2 |
j |
|
|
|
|
|
else |
|
|
|
|
|
j-- ; |
|
|
|
|
|
j += i ; |
|
|
|
|
As before, if the
condition is false, we want to jump. |
|
|
|
|
bne
$s1, $s2, ELSE # branch if !(
i == j ) |
|
|
|
addi $s1, $s1, 1
# i++ |
|
|
|
|
ELSE: addi $s2, $s2, -1 # else j-- |
|
|
|
|
add $s2, $s2, $s1
# j += i |
|
|
|
|
What's wrong with this
picture? |
|
|
|
|
|
|
|
|
|
Once we've done the
if-body, we need to jump over the else-body |
|
|
bne
$s1, $s2, ELSE # branch if !(
i == j ) |
|
|
addi $s1, $s1, 1
# i++ |
|
|
|
|
j NEXT # jump
over else |
|
|
|
ELSE: addi $s2, $s2, -1 # else j-- |
|
|
|
|
NEXT: add $s2, $s2, $s1 # j += i |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|