Digital Logic
- Derek Borden
- Sep 27, 2025
- 3 min read
Whew. A lot has happened since my last update on our CPU project, and I have been really busy. Unfortunately, a lot of stuff is still in the pipeline, so I still cannot write about these, but I do have a new development.
Bitwise Logic Operations

In addition to arithmetic, the ALU also needs to perform basic logic operations. These are housed in the Comparator, inside the ALU. These include AND, OR, XOR, and NOT. They are implemented by running each corresponding bit of the two 8-bit inputs through its own logic gate. There is nothing hard about these circuits, but they are important for a wide range of things like masking bits, comparisons, and control operations later on.
AND Gate
Function: Outputs 1 only if both inputs are 1.
A | B | A AND B |
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
Use: AND is commonly used for bit masking, allowing specific bits in a value to be isolated or cleared. It is also fundamental in control logic, where multiple conditions must be true for an action to occur.
OR Gate
Function: Outputs 1 if either input is 1.
A | B | A OR B |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
Use: OR is used to combine signals and set specific bits in a register. In CPUs, it is often used in flag logic and instruction decoding where multiple sources can trigger the same control signal.
NOT Gate
Function: Inverts the input.
A | NOT A |
0 | 1 |
1 | 0 |
Use: NOT is essential for bit inversion and is a core component of two’s complement arithmetic, which enables subtraction and negation. It is also used extensively in control logic to flip enable or select signals.
NAND Gate
Function: Outputs the inverse of AND.
A | B | A NAND B |
0 | 0 | 1 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Use: NAND gates are functionally complete, meaning any digital circuit can be built using only NAND gates. In practice, they are widely used in CPU design due to their efficiency in integrated circuits and their role in constructing more complex logic blocks.
NOR Gate
Function: Outputs the inverse of OR.
A | B | A NOR B |
0 | 0 | 1 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 0 |
Use: Like NAND, NOR is also functionally complete. NOR gates are commonly used in control logic and latches, where default-low behavior is desirable unless explicitly driven high.
XOR Gate (Exclusive OR)
Function: Outputs 1 if the inputs are different.
A | B | A XOR B |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Use: XOR is critical in arithmetic circuits, especially in adders where it determines sum bits. It is also used for comparisons, parity checks, and conditional bit toggling.
XNOR Gate (Exclusive NOR)
Function: Outputs 1 if the inputs are the same.
A | B | A XNOR B |
0 | 0 | 1 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
Use: XNOR is often used in equality comparisons, where matching bits indicate equivalence between two values. In CPUs, it can contribute to comparator circuits and zero-detection logic.
Buffer
Function: Outputs the same value as the input.
A | OUT |
0 | 0 |
1 | 1 |
Use: Buffers are used to strengthen signals and isolate circuit stages, ensuring clean logic levels across buses and long traces. Tri-state buffers are especially important in CPU designs, allowing multiple devices to share a bus without electrical conflicts.
At this point, our ALU can perform addition, subtraction, negation, and basic bitwise logic, which is a surprisingly large portion of what a CPU does at the hardware level. Now for registers and memory. Scary stuff.

Comments