Built-in project · no microcontroller

Adder from NAND gates

An 8-bit adder of 120 NAND gates, packaged six chips deep. Unpack it a level at a time. There is no microcontroller in it: the simulator solves the 6 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.

Teaching? Assign it to your class in one click.

Advanced About 20 minutes to build and run. Runs in your browser. Free, and no account needed.

The circuit runs here once the page has loaded.

What you'll learn

  • Binary addition with a ripple carry
  • Half adders and full adders
  • How XOR, AND, OR and NOT are built from NAND
  • Overflow and the carry out bit
  • Hierarchy: big chips made of smaller chips
  • Difficulty: Advanced
  • Time: About 20 minutes
  • Parts: 125

How it works

This circuit has no microcontroller and no code. Two 8-bit number switches feed the A and B inputs of one chip called ADDER8, and a bit switch feeds its carry input, CIN. Press Run and the simulator solves the gates.

The chip outputs the sum on S0 to S7, which a number display shows. If the answer needs a ninth bit, the COUT pin lights a bit lamp. For example, 200 + 100 shows 44 with the lamp lit, because 300 minus 256 is 44.

Inside, ADDER8 is two 4-bit adders, which are four full adders each, which are half adders and gates, down to 120 NAND gates in all. Select the chip and press Unpack to open it one level at a time.

Parts list

125 parts, plus the jumper wires. Every one is in the editor's parts bin.

  • 2 × Number switch
  • 1 × Bit switch
  • 120 × Logic gateIn Logic Lab Kit.
  • 1 × Number display
  • 1 × Bit lamp

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
ADDER8 chip pin A0Number switch (1) pin D0
ADDER8 chip pin A1Number switch (1) pin D1
ADDER8 chip pin A2Number switch (1) pin D2
ADDER8 chip pin A3Number switch (1) pin D3
ADDER8 chip pin A4Number switch (1) pin D4
ADDER8 chip pin A5Number switch (1) pin D5
ADDER8 chip pin A6Number switch (1) pin D6
ADDER8 chip pin A7Number switch (1) pin D7
ADDER8 chip pin B0Number switch (2) pin D0
ADDER8 chip pin B1Number switch (2) pin D1
ADDER8 chip pin B2Number switch (2) pin D2
ADDER8 chip pin B3Number switch (2) pin D3
ADDER8 chip pin B4Number switch (2) pin D4
ADDER8 chip pin B5Number switch (2) pin D5
ADDER8 chip pin B6Number switch (2) pin D6
ADDER8 chip pin B7Number switch (2) pin D7
ADDER8 chip pin CINBit switch pin Q
Number display pin D0ADDER8 chip pin S0
Number display pin D1ADDER8 chip pin S1
Number display pin D2ADDER8 chip pin S2
Number display pin D3ADDER8 chip pin S3
Number display pin D4ADDER8 chip pin S4
Number display pin D5ADDER8 chip pin S5
Number display pin D6ADDER8 chip pin S6
Number display pin D7ADDER8 chip pin S7
Bit lamp pin AADDER8 chip pin COUT

The note on the canvas

Word for word, as it sits beside the circuit in the editor.

Press Run, then click A or B to count them up. The adder is 120 NAND gates, six chips deep. Select it and press Unpack to look inside, one level at a time.

The notes that come with it

There is no microcontroller in this one, so nothing is compiled: the simulator solves the circuit itself. The file in the editor is the notes that come with it.

sketch.ino
// An 8-bit adder, built from nothing but NAND gates.
//
// There is no microcontroller here and nothing to compile: press Run and the
// simulator solves the gates. Click A or B to count it up by one, or type a
// value into its properties.
//
//   A + B + CIN = S, with COUT for the ninth bit
//   200 + 100 + 0 = 300, which shows as 44 with COUT lit (300 - 256 = 44)
//
// The adder is one chip, ADDER8. Select it and press Unpack to open it:
//
//   ADDER8      two ADDER4 chips, the carry running from one to the other
//   ADDER4      four FULL ADDERs in a ripple chain
//   FULL ADDER  two HALF ADDERs and an OR
//   HALF ADDER  an XOR for the sum and an AND for the carry
//   XOR         four NAND gates
//   AND, OR     NAND gates and NOT
//   NOT         one NAND gate with its inputs tied together
//
// 120 NAND gates in all. The lessons that build every one of these chips are
// on the path From gates to a computer, under Learn.

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The display shows a small number when A plus B is large This project
    The display only has 8 bits, so it wraps at 256. Check the COUT lamp: if it is lit, add 256 to what you read.
  • Nothing changes when you click the switches This project
    Press Run first. The gates are only solved while the simulation is running.
  • The count looks reversed. The bit order is read the wrong way, with bit 0 as the least significant. Number switch
    Check which pin is bit 0 and wire it to the lowest input of the chip. Test with a value like 1, where only the least significant bit is high.
  • Chip inputs are left floating, or the switch signals are wired without a common ground. Number switch
    Connect the number switch output to every input you use, and tie the unused inputs high or low as the chip needs. Join the grounds.
  • The chip input does not respond to the switch. Bit switch
    Check that the switch ground is shared with the chip ground, and that the chip is powered. Make sure the output goes to the right input pin.
  • Logic levels look wrong. Bit switch
    The switch gives a clean 0 or 1, but the chip only sees that if its supply matches. Check the supply voltage is in the chip's allowed range.
  • The output sits at a random level. Logic gate
    Never leave a gate input floating. Tie unused inputs to the supply or ground, or add pull-up or pull-down resistors to the inputs.
  • The truth table seems wrong. Logic gate
    Check which gate type you chose. NAND, NOR and XOR invert or differ from AND and OR. Test each input combination with LEDs at the output.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.