ST20-C1 STMICROELECTRONICS [STMicroelectronics], ST20-C1 Datasheet - Page 46

no-image

ST20-C1

Manufacturer Part Number
ST20-C1
Description
Instruction Set Reference Manual
Manufacturer
STMICROELECTRONICS [STMicroelectronics]
Datasheet
4.7 Evaluation of boolean expressions
The following shows the correspondence between C logical expressions and ST20-C1
instructions. X and Y represent expressions,and K represents a constant. The symbol
‘ ’ is a logical NOT (see section 4.7.1).
Further optimizations can be made to the ‘not equals’ comparison when followed by a
conditional jump.
4.7.1
If zero represents false and 1 represents true, then logical NOT can be performed by
eqc 0 .
4.7.2
For evaluation of logical AND and OR operations, the instruction sequence depends
on whether strict or non-strict evaluation is used, i.e. whether both operands are
always evaluated. This is important if side-effects may occur, such as a trap, or if the
second operand is not always defined, as in:
In this example, ptr->tag is not defined if ptr is NULL. For languages such as ANSI
C, non-strict evaluation is required, so the following short-cuts must be used:
For non-strict evaluation, the following laws should be applied to the compilation of
conditional expressions before code is generated to ensure that the jump is taken as
early as possible:
46/205
if ((ptr != NULL) && (ptr->tag == TAG_VAL)) ...
true
false
! X
X == Y
X != Y
X == K
X != K
X > Y
X < Y
X >= Y
X <= Y
X != Y; cj L
X != 0; cj L
Evaluation of NOT
Evaluation of AND and OR
X OR Y
X AND Y
(X OR Y); cj L
(X AND Y); cj L = X; cj L; Y; cj L
(X AND Y)
(X OR Y)
= ( X) OR ( Y)
= ( X) AND ( Y)
= ( X); cj M; Y; cj L; M:
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
ldc 1
ldc 0
X; Y; sub; eqc 0
X; eqc K
X; Y; gt
Y; X; gt
X; Y; sub; cj L
X; cj L
X; cj L; Y; L:
(X)
(X; Y; sub; eqc 0)
(X; eqc K)
(Y; X; gt)
(X; Y; gt)
( (X); cj L; (Y); L:)
[= (X; cj L; Y; L:) ]
[= ( X); cj L; ( Y); L: ]

Related parts for ST20-C1