COA Notes
Logic micro-operations: AND, OR, XOR, NOT operations on register contents with applications.
Introduction
While arithmetic micro-operations deal with numerical calculations, logic micro-operations perform bitwise Boolean operations on register contents. They don't treat the register as a number — instead, they operate on each bit independently. These operations are incredibly powerful for tasks like masking specific bits, setting flags, clearing fields, toggling states, and packing/unpacking data. Every programmer who's done bit manipulation is using logic micro-operations at the hardware level.
The Four Basic Logic Micro-operations
AND (∧)
Each bit of the result is 1 only if BOTH corresponding input bits are 1.
| R1 | 1 0 1 1 0 1 1 0 |
| R2 | 1 1 0 1 0 0 1 1 |
| R1 | 1 0 0 1 0 0 1 0 |
Primary use: Masking (clearing specific bits) To clear bits 4-7 while keeping bits 0-3:
OR (∨)
Each bit of the result is 1 if EITHER (or both) input bits are 1.
| R1 | 1 0 1 1 0 0 0 0 |
| R2 | 0 0 0 0 1 1 0 1 |
| R1 | 1 0 1 1 1 1 0 1 |
Primary use: Setting specific bits To set bits 0 and 2 without disturbing others:
XOR (⊕)
Each bit of the result is 1 if the input bits are DIFFERENT.
| R1 | 1 0 1 1 0 1 1 0 |
| R2 | 1 1 0 1 0 0 1 1 |
| R1 | 0 1 1 0 0 1 0 1 |
Primary uses:
- Toggling bits: XOR with 1 flips a bit; XOR with 0 preserves it
- Comparing: If R1 ⊕ R2 = 0, then R1 = R2
- Clearing a register: R1 ← R1 ⊕ R1 (always gives 0, faster than loading 0)
- Swapping without temp: A⊕=B, B⊕=A, A⊕=B
NOT (Complement)
Each bit is inverted: 0→1, 1→0.
Primary use: One's complement, creating masks
Complete Set of Logic Micro-operations
With two input variables (per bit position), there are 2⁴ = 16 possible logic functions:
| Operation | Result | Name |
|---|---|---|
| F = 0 | Clear | Always zero |
| F = A ∧ B | AND | Both bits 1 |
| F = A ∧ B̄ | Inhibit | A but not B |
| F = A | Transfer A | Copy A |
| F = Ā ∧ B | Inhibit | B but not A |
| F = B | Transfer B | Copy B |
| F = A ⊕ B | XOR | Different bits |
| F = A ∨ B | OR | Either bit 1 |
| F = (A ∨ B)' | NOR | Neither bit 1 |
| F = (A ⊕ B)' | XNOR | Same bits |
| F = B̄ | Complement B | Invert B |
| F = A ∨ B̄ | --- | A or not B |
| F = Ā | Complement A | Invert A |
| F = Ā ∨ B | --- | Not A or B |
| F = (A ∧ B)' | NAND | Not both 1 |
| F = 1 | Set | Always one |
In practice, processors implement AND, OR, XOR, and NOT — all 16 functions can be derived from these four.
Hardware Implementation
Logic Unit Circuit
A logic unit for n-bit registers consists of n identical 1-bit slices:
Select lines (S1, S0) choose which operation's output reaches the result:
| S1 | S0 | Output |
|---|---|---|
| 0 | 0 | A AND B |
| 0 | 1 | A OR B |
| 1 | 0 | A XOR B |
| 1 | 1 | NOT A |
Practical Applications
Bit Masking
Extract specific bit fields from a register:
Setting Flags
Set specific control bits:
Clearing Flags
Clear specific bits:
Toggling
Flip specific bits:
Testing Bits
Check if a specific bit is set:
Packing/Unpacking Data
Combine two 4-bit values into one 8-bit register:
Logic vs Arithmetic Operations
| Feature | Logic Micro-ops | Arithmetic Micro-ops |
|---|---|---|
| Bit interaction | Each bit independent | Carries propagate between bits |
| Number interpretation | Bits have no numeric meaning | Bits form a number |
| Carry | No carry generation | Carry is essential |
| Speed | Faster (no carry chain) | Slightly slower (carry propagation) |
| Use case | Bit manipulation, masking | Mathematical computation |
Key Takeaways
- Logic micro-operations perform bitwise Boolean operations — each bit is processed independently
- The four essential operations: AND (mask/clear), OR (set), XOR (toggle/compare), NOT (invert)
- No carry propagation occurs — making logic operations inherently faster than arithmetic
- AND with a mask clears bits; OR with a mask sets bits; XOR with a mask toggles bits
- XOR of a register with itself clears it (R←R⊕R = 0) — the fastest way to zero a register
- All 16 possible two-variable logic functions exist, but AND, OR, XOR, NOT suffice in practice
- Logic and arithmetic circuits are combined in the ALU, selected by control signals
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Logic Micro-operations.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Computer Organization & Architecture topic.
Search Terms
computer-organization, computer organization & architecture, computer, organization, register, transfer, and, microoperations
Related Computer Organization & Architecture Topics