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
Not
gate, as it is the simplest modification of aNand
gate and is fundamental to building other logic gates.
- Start with the
And
- Next, construct the
And
gate using theNand
andNot
gates. TheAnd
gate forms a basic building block for many other chips.
- Next, construct the
Or
- Build the
Or
gate usingNand
gates, which will also utilize theNot
gate. TheOr
gate is essential for creating theXor
gate and various multiplexers.
- Build the
Xor
- With
Nand
,Not
, andOr
gates at your disposal, you can now construct theXor
gate, which is slightly more complex and used in various computing functions.
- With
Mux
- The basic
Mux
(Multiplexer) can be built usingAnd
,Or
, andNot
gates. This component is foundational for creating more complex multiplexers.
- The basic
Dmux
- Construct the
Dmux
(Demultiplexer) next, using previously built gates likeNot
andAnd
. This chip is crucial for distributing signals in circuits.
- Construct the
Not16
- Construct the
Not16
gate, which extends the functionality of theNot
gate to 16-bit inputs. This requires simply replicating theNot
operation across 16 channels.
- Construct the
And16
- Similarly, build the
And16
gate, which is an extension of theAnd
gate to 16-bit inputs.
- Similarly, build the
Or16
- Follow with
Or16
, which is an extension of theOr
gate to handle 16-bit inputs.
- Follow with
Or8Way
- The
Or8Way
takes an 8-input and outputs true if any input is true. This can be built using theOr
andOr16
logic.
- The
Mux16
- Build the
Mux16
, which is a 16-bit version of theMux
, using 16 sets ofMux
gates to handle 16-bit inputs.
- Build the
Mux4Way16
- This is a 4-way 16-bit multiplexer, and can be built using multiple
Mux16
gates, 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
Mux8Way16
usingMux4Way16
and other necessary logic components to expand the selection capability.
- Construct the
Dmux4Way
- Build the
Dmux4Way
, a more complex version of theDmux
, using additionalDmux
and logic gates to distribute a single input to one of four outputs.
- Build the
Dmux8Way
- Finally, construct the
Dmux8Way
, which extends theDmux4Way
functionality 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.