Master the fundamental concepts of digital logic & boolean algebra through this focused micro-challenge.
The NAND gate (NOT-AND) outputs 0 only when both inputs are 1. Every other basic gate can be built from NAND alone, which is why foundry standard-cell libraries often ship millions of identical NAND2 cells.
Truth table for NAND(A, B):
| A | B | Out |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
NAND(A, A)NAND(NAND(A,B), NAND(A,B))NAND(NOT A, NOT B)For example, NOT(1) becomes NAND(1,1) = 0, and AND(1,0) chains two NAND calls to yield 0.
cLoading…
For this exercise, you will implement each derived gate as a pure function of nand(a, b) only. This task asks you to prove universality in code, the same reduction step nand2tetris uses before students wire their first ALU.
Keep the relevant datasheet, ISA manual, or architecture textbook chapter open while you implement. When your output disagrees with the reference trace on the same program, the bug is usually a mis-decoded opcode, a stale register read, or a flag bit left unchanged after arithmetic.
For this exercise, you will use those habits while implementing the requirement in the starter code. Microarchitectural product names change across CPU generations, but the control ideas (fetch, bypass, cache lines, vector lanes) stay stable enough to debug from first principles.
Implement all basic logic gates using only NAND gates.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github