|
|
|
|
|
|
|
|
|
|
|
|
|
|
Conditional: compound
condition |
|
|
|
|
|
|
|
|
if-else
with compound AND
condition: short-circuiting |
|
|
|
|
if ( i == j && i
== k ) |
// if ( <cond1>
&& <cond2> ) |
|
|
|
i++ ; |
|
// if body |
|
|
|
|
|
|
else |
|
$s1 |
i |
|
|
|
|
j-- ; |
|
// else body |
$s2 |
j |
|
|
|
|
j = i + k ; |
|
|
|
$s3 |
k |
|
|
|
|
|
|
|
|
|
Let <cond1> stand for (i == j) and <cond2> stand for (i == k). |
|
|
|
Short-circuiting occurs when <cond1> evaluates to false. |
|
|
|
|
The control flow then
jumps over <cond2> and the
if-body. |
|
|
|
If <cond1> evaluates to true, we also want to check <cond2>. |
|
|
|
|
If <cond2> evaluates false, we again jump, this time over the if-body, |
|
|
|
and to the else-body. |
|
|
|
|
If <cond2> is true, we fall-through to the if-body. |
|
|
|
|
|
|
|
bne
$s1, $s2, ELSE # cond1:
branch if !( i == j ) |
|
|
bne
$s1, $s3, ELSE # cond2:
branch if !( i == k ) |
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|