Control
flow includes the study of Boolean expressions, which have two roles.
1.
They can be computed and treated similar to integers or real. Once can declare Boolean
variables, there are boolean constants and boolean operators. There are also
relational operators that produce Boolean values from arithmetic operands.
2.
They are used in certain statements that alter the normal flow of control.
Boolean
Expressions
One
question that comes up with Boolean expressions is whether both operands need
be evaluated. If we need to evaluate A OR B and find that A is true, must we
evaluate B? For example, consider evaluating A=0 OR 3/A < 1.2 when A is
zero.
This
comes up some times in arithmetic as well. Consider A*F(x). If the compiler
knows that for this run A is zero must it evaluate F(x)? Functions can have
side effects, do it could be a potential problem .
Short-Circuit
Code
This
is also called jumping code. Here the Boolean operators AND, OR, and NOT do not
appear in the generated instruction stream. Instead we just generate jumps to
either the true branch or the false branch.
Example:
if
( x < 100 II x > 200
&& x != y ) x = 0;
if
x < 100 goto L2
if
False x > 200 goto L1
if
False x != y goto L1
L2:
x = 0
L1:
0 comments