Jonathan A. Titus

Microcomputer Pioneer

Home Jon Titus Mark-8 Lessons Timeline Links Comm Board About

Lesson 3: Boolean Logic

Unary and Binary Operators

Symbol Usage Binary Operation
& A & B AND
| A | B OR
^ A ^ B XOR
~ ~A NOT

Figure 3-1 Table of Boolean Operators

Unary and binary operators only are usable within expressions. Expressions are evaluated during assembly of the program and are useful in making the code easier to understand, usually by breaking up constants into smaller units which are easier to understand. For example, if B is in actuality "going to the beach and it is sunny outside", then it may be broken up into an equivalent statement. If C is "going to the beach" and D is "it is sunny outside", then the expression C&D is equivalent to B. Though very helpful in some situations, use of expressions for runtime calculations should be avoided. Instructions should be used for runtime calculations.

B = "going to the beach
and it is sunny outside"

(B is a constant)
C = "going to the beach"
D = "it is sunny outside"

(C and D are constants)

Fig 3-2 Equivalent Statements


Instruction Parameters Meaning
AND dest, src Logical AND
OR dest, src Logical OR
XOR dest, src Logical XOR
NOT dest Logical NOT

Figure 3-1 Table of Boolean Operators

Instructions are not evaluated during code assembly as operators are. Therefore, variables may be used in conjunction with constants in the boolean instructions (except for NOT). For all of the boolean instructions, the Z (zero) flag is set when the result is zero. They are extremely useful in constructing conditional if/else statements when the if/else directives aren't ideal, such as when cycles must be counted and synchronized to some outside I/O device.