4 Using ST20-C1 instructions
In other languages, evaluation of boolean expressions may be strict (for example, ADA
gives the programmer the choice) and so both expressions in dyadic logical opera-
tions may need to be evaluated.
Where false is represented by 0, and true is represented by any fixed bit pattern other
than 0 (e.g. true is always 1, or true is always -1), then the following transformations
apply:
X OR Y
=
X AND Y
=
X BITOR Y
X BITAND Y
and the bitwise instructions given in section 4.8 can be used:
Note that even for some non-strict evaluations, the above sequence may be prefer-
able. Where Y is a simple boolean expression such as a local variable, its evaluation
does not cause any side-effects, and so it does no harm to implement a non-strict
evaluation using a bitwise operation.
4.8 Bitwise logic and bit operations
Bitwise logic and bit operations are provided by the instructions listed in Table 4.10.
Mnemonic
Name
and
and
or
or
xor
exclusive or
not
bitwise not
bitld
bit load
bitst
bit store
bitmask
bit mask
rmw
memory read modify write
Table 4.10 Bitwise logic and bit instructions
The not operation has only one operand that is taken from Areg. The result of this,
which is a bitwise inversion of all bits in the operand, is loaded into Areg, leaving Breg
and Creg unaffected.
and, or and xor are bitwise logical operations on two operands that are taken from
Areg and Breg. For each, the result is loaded into Areg. The data previously held in
Creg is popped into Breg and the initial Areg is left in Creg. These operations are
commutative.
bitld, bitst and bitmask are used for setting, clearing and testing bits of a word. bitld
returns the value of a single bit from a value in Breg, bitst sets or clears a single bit
and bitmask creates a mask with a single bit set. In each case the bit number is
initially in Areg and the result is put in Areg. For bitld and bitst, the value containing
the bit to be tested, set or cleared is initially in Breg.
47/205
®