if ( C )
{
s1;
s2;
...
}
|
give rise to an assembler program with the following structure:
instructions to perform a compare
specified by the condition C
branch of FALSE of the condition C to label IfEnd
instructions to perform s1
instructions to perform s2
....
IfEnd:
|
if ( C )
{
s1;
s2;
...
}
else
{
t1;
t2;
...
}
|
give rise to an assembler program with the following structure:
instructions to perform a compare
specified by the condition C
branch of FALSE of the condition C to label Else
instructions to perform s1
instructions to perform s2
....
bra IfEnd
Else:
instructions to perform t1
instructions to perform t2
....
IfEnd:
|
|
// x = max of a and b when c > 0
// otherwise, x = min of a and b
int x, a, b, c;
if ( c > 0 )
{
// Find maximum
if ( a > b )
{
x = a;
}
else
{
x = b;
}
}
else
{
// Find minimum
if ( a < b )
{
x = a;
}
else
{
x = b;
}
}
|
|
if ( c > 0 )
{
"then" body stripped
}
else
{
"else" body stripped
}
|
+----------------+ FALSE (branch)
| test c > 0 | --------+
+----------------+ |
| True |
V |
+-----------------+ |
| code for body | |
| of "then" part | |
+-----------------+ |
| |
+------------------------------+ (jump over "else" part)
| |
| |
If1_Else: +<-----------------+ |
| |
V |
+-----------------+ |
| code for body | |
| of "else" part | |
+-----------------+ |
| |
| |
If1_End: +<-----------------------------+
|
V
|
move.l c,d0
cmp.l #0,d0 Tests: c ?? 0
ble If1_Else Branch when !(c < 0) <=> c <= 0
.....
code for body of "then" part
.....
bra If1_End
If1_Else:
.....
code for body of "else" part
.....
If1_End:
|
if ( a > b )
{
x = a;
}
else
{
x = b;
}
|
+----------------+ FALSE (branch)
| test a > b | --------+
+----------------+ |
| True |
V |
+-----------------+ |
| x = a | |
+-----------------+ |
| |
+------------------------------+ (jump over "else" part)
| |
| |
If2_Else: +<-----------------+ |
| |
V |
+-----------------+ |
| x = b | |
+-----------------+ |
| |
| |
If2_End: +<-----------------------------+
|
V
|
move.l a,d0
cmp.l b,d0 Tests: a ?? b
ble If2_Else Branch when !(a > b) <=> a <= b
move.l a,d0
move.l d0,x
bra If2_End
If2_Else:
move.l b,d0
move.l d0,x
If2_End:
|
if ( a < b )
{
x = a;
}
else
{
x = b;
}
|
+----------------+ FALSE (branch)
| test a < b | --------+
+----------------+ |
| True |
V |
+-----------------+ |
| x = a | |
+-----------------+ |
| |
+------------------------------+ (jump over "else" part)
| |
| |
If3_Else: +<-----------------+ |
| |
V |
+-----------------+ |
| x = b | |
+-----------------+ |
| |
| |
If3_End: +<-----------------------------+
|
V
|
move.l a,d0
cmp.l b,d0 Tests: a ?? b
bge If3_Else Branch when !(a < b ) <=> a >= b
move.l a,d0
move.l d0,x
bra If3_End
If3_Else:
move.l b,d0
move.l d0,x
If3_End:
|
move.l c,d0
cmp.l #0,d0 Tests: c ?? 0
ble If1_Else Branch when c <= 0
.....
code for body of "then" part
.....
bra If1_End
If1_Else:
.....
code for body of "else" part
.....
If1_End:
|
move.l c,d0
cmp.l #0,d0 Tests: c ?? 0
ble If1_Else Branch when c <= 0
-----------------------------------------------------------------------
move.l a,d0
cmp.l b,d0 Tests: a ?? b
ble If2_Else Branch when a <= b
move.l a,d0
move.l d0,x
bra If2_End
If2_Else:
move.l b,d0
move.l d0,x
If2_End:
-----------------------------------------------------------------------
bra If1_End
If1_Else:
.....
code for body of "else" part
.....
If1_End:
|
move.l c,d0
cmp.l #0,d0 Tests: c ?? 0
ble If1_Else Branch when c <= 0
-----------------------------------------------------------------------
move.l a,d0
cmp.l b,d0 Tests: a ?? b
ble If2_Else Branch when a <= b
move.l a,d0
move.l d0,x
bra If2_End
If2_Else:
move.l b,d0
move.l d0,x
If2_End:
-----------------------------------------------------------------------
bra If1_End
If1_Else:
----------------------------------------------------------------------
move.l a,d0
cmp.l b,d0 Tests: a ?? b
bge If3_Else Branch when a >= b
move.l a,d0
move.l d0,x
bra If3_End
If3_Else:
move.l b,d0
move.l d0,x
If3_End:
----------------------------------------------------------------------
If1_End:
|
|