Built-in project · no microcontroller

Your first computer

A CPU of about four thousand NAND gates running a program from a ROM, with a terminal. Change the program and run yours. There is no microcontroller in it: the simulator solves the 5 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 30 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

  • How NAND gates build up into a CPU
  • A program counter fetching instructions from a ROM
  • Registers, an ALU and a little RAM working together
  • Running and changing a program in assembly
  • Difficulty: Advanced
  • Time: About 30 minutes
  • Parts: 4027

How it works

This is a whole computer made of logic gates. The Kestrel CPU is one chip of about four thousand NAND gates. A step clock ticks it, and it reads its instructions from a program ROM, one address at a time.

Press Run, then set RESET to 1 for a tick to send the program counter back to address 0. The CPU then runs the ROM program. Whatever it sends out goes to the terminal, which prints each byte. Click the ROM to change the program and run your own.

Parts list

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

  • 1 × Step clock
  • 1 × Bit switch
  • 1 × Program ROM
  • 4019 × Logic gateIn Logic Lab Kit.
  • 4 × Constant bit
  • 1 × Terminal

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
KESTREL chip pin CLKStep clock pin CLK
Terminal pin CLKStep clock pin CLK
KESTREL chip pin RESETBit switch pin Q
KESTREL chip pin PC0Program ROM pin A0
KESTREL chip pin PC1Program ROM pin A1
KESTREL chip pin PC2Program ROM pin A2
KESTREL chip pin PC3Program ROM pin A3
KESTREL chip pin PC4Program ROM pin A4
KESTREL chip pin PC5Program ROM pin A5
KESTREL chip pin PC6Program ROM pin A6
KESTREL chip pin PC7Program ROM pin A7
KESTREL chip pin C0Program ROM pin C0
KESTREL chip pin C1Program ROM pin C1
KESTREL chip pin C2Program ROM pin C2
KESTREL chip pin C3Program ROM pin C3
KESTREL chip pin C4Program ROM pin C4
KESTREL chip pin C5Program ROM pin C5
KESTREL chip pin C6Program ROM pin C6
KESTREL chip pin C7Program ROM pin C7
KESTREL chip pin K0Program ROM pin K0
KESTREL chip pin K1Program ROM pin K1
KESTREL chip pin K2Program ROM pin K2
KESTREL chip pin K3Program ROM pin K3
KESTREL chip pin K4Program ROM pin K4
KESTREL chip pin K5Program ROM pin K5
KESTREL chip pin K6Program ROM pin K6
KESTREL chip pin K7Program ROM pin K7
Terminal pin D0KESTREL chip pin OUT0
Terminal pin D1KESTREL chip pin OUT1
Terminal pin D2KESTREL chip pin OUT2
Terminal pin D3KESTREL chip pin OUT3
Terminal pin D4KESTREL chip pin OUT4
Terminal pin D5KESTREL chip pin OUT5
Terminal pin D6KESTREL chip pin OUT6
Terminal pin D7KESTREL chip pin OUT7
Terminal pin WEKESTREL chip pin OUTW

The note on the canvas

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

Press Run, then click RESET to 0. The Kestrel CPU is about four thousand NAND gates. Click the ROM to change the program.

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
// Your first computer: a CPU built from NAND gates, running a program.
//
// Press Run, then click RESET to set it to 0. The CPU starts at address 0 of
// the program ROM and the terminal prints what it sends.
//
//   step clock   200 ticks a second; set its mode to step to go one
//                instruction a click
//   RESET        at 1, the next tick sets the program counter to 0
//   program ROM  click it: the program is Kestrel assembly in its properties
//   KESTREL      the CPU, one chip; Unpack it to see CONTROL, REGS4, ALU8,
//                RAM8 and PC, and keep unpacking down to the NAND gates
//   terminal     prints each byte OUT sends it
//
// The Kestrel has four registers, R0 to R3, eight bytes of RAM and sixteen
// instructions. The help article on the program ROM lists them. Change the
// program, press Run and RESET again, and it runs yours.
//
// Every chip in it is built in the lessons on the path From gates to a
// computer, under Learn.

Troubleshooting

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

  • The terminal prints nothing This project
    Press Run, then click RESET to 0 so the CPU starts at address 0 of the ROM.
  • It runs too fast to follow This project
    Set the step clock to step mode and click once per instruction.
  • Your own program does not run This project
    After changing the ROM, press Run and RESET again so it starts from the beginning.
  • Counters do not change when expected. Step clock
    Check that the clock output goes to the clock input of the counter and that the counter's reset and enable pins are in the right state.
  • The count seems to jump or skip. Step clock
    Make sure the clock is a clean edge. A bouncing mechanical switch can give several pulses, so use a debounced source for counting.
  • 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 CPU runs odd instructions or stops, because the program counter reads past the end or the address wiring is wrong. Program ROM
    Check that the address lines go to the program counter in order, with bit 0 as the lowest. The ROM holds 256 instructions, so keep programs inside that.

Change it and keep it

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