if ( condition ) ----> |
statement |
+--------------+ FALSE
| condition |--------+
+--------------+ |
| |
| TRUE |
| |
V |
statement |
| |
| |
V |
+<---------------+
|
V
Evaluate "condition" (CMP)
FALSE
Branch on the FALSE outcome of "condition" to here (A:) ----+
| |
| TRUE |
| |
V |
Translate "statement" into assembler code |
| |
| |
V |
A: +<------------------------------------------------+
|
V
int x; Assembler construct for this if-statement:
if ( x < 0 ) MOVE.L x, D0
x = -x; CMP.L #0, D0 Compares x against 0
BGE L1 Skip over "x=-x" when x >= 0
MOVE.L x, D0 (you can omit this, because D0
already has x...)
NEG.L D0
MOVE.L D0, x
L1: ...
The flow chart of the program is:
|
int x; Assembler construct for this if-statement:
int y;
int help;
if ( x > y ) MOVE.L x, D0
{ // Swap x and y CMP.L y, D0 Compares x against y
help = x; BLE L1 Skip when x <= y
x = y;
y = help; MOVE.L y, x Note: we don't need a "help"
} MOVE.L D0, y variable to achieve swapping
The data reg. D0 is
the "help" variable...
L1: ...
The flow chart of the program is:
|