nand2Tetris - Week 1 - Logic Gates
Logic Gates
- A technique for implementing Boolean function using logic gates
- Logic gates:
- Elementary (Nand, And , Or, Not…)
- Composite (Mux, Adder,….)
Elementary Logic Gates
NAND
Gate Diagram:

Function specification:
if (a==1 and b==1)
then out=0 else out=1
Truth Table
| x | y | NAND |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |

Circuit implementation

The following course does not deal with physical implementation of gates
- Circuits, transistors, relays, etc is part of Electrical Engineering and not computer science.
Hardware Simulator
Nand give is an elementary gate already provided in the course so no implementation need for this, we will build all other gates using Nand Gates.
Building logic gates and chips in a structured and incremental manner is crucial in a course like nand2tetris, where each component builds upon the functionality of previously constructed ones. Below is a recommended sequence for building the listed gates and chips, starting with the simplest and moving towards the more complex. This order ensures that each component you build can be tested and used in the subsequent, more complex components.
Recommended Order for Building Gates and Chips:
Not
- Start with the
Notgate, as it is the simplest modification of aNandgate and is fundamental to building other logic gates.
- Start with the
And
- Next, construct the
Andgate using theNandandNotgates. TheAndgate forms a basic building block for many other chips.
- Next, construct the
Or
- Build the
Orgate usingNandgates, which will also utilize theNotgate. TheOrgate is essential for creating theXorgate and various multiplexers.
- Build the
Xor
- With
Nand,Not, andOrgates at your disposal, you can now construct theXorgate, which is slightly more complex and used in various computing functions.
- With
Mux
- The basic
Mux(Multiplexer) can be built usingAnd,Or, andNotgates. This component is foundational for creating more complex multiplexers.
- The basic
Dmux
- Construct the
Dmux(Demultiplexer) next, using previously built gates likeNotandAnd. This chip is crucial for distributing signals in circuits.
- Construct the
Not16
- Construct the
Not16gate, which extends the functionality of theNotgate to 16-bit inputs. This requires simply replicating theNotoperation across 16 channels.
- Construct the
And16
- Similarly, build the
And16gate, which is an extension of theAndgate to 16-bit inputs.
- Similarly, build the
Or16
- Follow with
Or16, which is an extension of theOrgate to handle 16-bit inputs.
- Follow with
Or8Way
- The
Or8Waytakes an 8-input and outputs true if any input is true. This can be built using theOrandOr16logic.
- The
Mux16
- Build the
Mux16, which is a 16-bit version of theMux, using 16 sets ofMuxgates to handle 16-bit inputs.
- Build the
Mux4Way16
- This is a 4-way 16-bit multiplexer, and can be built using multiple
Mux16gates, controlled by additional logic gates to select among the 4 inputs.
- This is a 4-way 16-bit multiplexer, and can be built using multiple
Mux8Way16
- Construct the
Mux8Way16usingMux4Way16and other necessary logic components to expand the selection capability.
- Construct the
Dmux4Way
- Build the
Dmux4Way, a more complex version of theDmux, using additionalDmuxand logic gates to distribute a single input to one of four outputs.
- Build the
Dmux8Way
- Finally, construct the
Dmux8Way, which extends theDmux4Wayfunctionality to eight outputs. This involves additional layers of demultiplexing.
- Finally, construct the
Building Approach:
Each gate or chip should be fully tested before proceeding to build more complex components that depend on it. Use the testing scripts provided by nand2tetris to ensure each component works correctly according to the specifications. This order of building ensures a logical progression, making debugging easier and helping solidify your understanding of digital logic as each new component introduces additional complexity.