|
|
|
|
|
|
|
|
|
|
|
|
|
|
Conditional: compound
condition |
|
|
|
|
|
|
|
|
if-else
with compound OR
condition: short-circuiting |
|
|
|
|
use <cond1> to stand for (i == j) and <cond2> to stand for (i == k). |
|
|
if ( <cond1> ||
<cond2> ) |
|
|
|
|
i++ ; |
|
// if-body |
|
$s1 |
i |
|
|
|
|
else |
|
|
|
$s2 |
j |
|
|
|
|
j-- ; |
|
// else-body |
|
$s3 |
k |
|
|
|
|
j = i + k ; |
|
|
|
|
|
|
|
|
Short-circuiting occurs when <cond1> evaluates to true |
|
|
|
|
If <cond1> is false, we also want to check <cond2> |
|
|
|
|
If <cond2> is false, we now jump to the else-body. |
|
|
|
If <cond2> is true, we fall through to the if-body. |
|
|
|
|
|
|
|
beq
$s1, $s2, IF # cond1:
branch if ( i == j ) |
|
|
|
|
|
#
Notice branch on TRUE |
|
|
|
bne
$s1, $s3, ELSE # cond2:
branch if ! ( i == k ) |
|
|
IF: addi $s1, $s1, 1 #
if-body: i++ |
|
|
|
|
j NEXT # jump
over else |
|
|
|
ELSE: addi $s2, $s2,
-1 # else-body: j-- |
|
|
|
|
NEXT: add $s2, $s1, $s3 # j = i + k |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|