About 6 months ago, I found a series of videos on youtube by Ben Eater, where he goes through the entire process of making an 8-bit computer, following the SAP 1 (simple as possible) architecture designed by Albert Paul Malvino. The below picture is the block diagram for this architecture for anyone curious.
The basic idea is that you have one central bus that most other system components operate on, all of which are kept in sync by the system clock. In a very basic program that adds 2 numbers, the instruction register sequences through the program based on the state of the program counter, values from memory are placed into the appropriate registers, and the ALU adds the numbers in the registers and outputs the result to the output register, which can then be displayed. The process is really fascinating when you consider how much needs to happen in order to just carry out 2 + 2 = 4, and then imagine what the equivalent must be for doing something like rendering a video on a monitor.
Anyway, Ben’s series completely blew me away, and I highly recommend it if you have an interest in electronics or if you just want to learn how computers in general work. All of the basic concepts that are utilized in the SAP 1 apply to modern computers as well, just on a much larger and more complex scale.
I have some education in electronics, and have been doing hobbyist type stuff for awhile, but I guess the concept of designing and building your own computer (albeit a very simple one) never really crossed my mind. This is also entirely different than building a modern PC, which I have done multiple times in the past, since that is essentially no different than building a piece of furniture from IKEA.
Doing something like Ben did is unique. The architecture, control logic, instruction set, etc. were designed from the ground up. Based on existing ideas and designs, yes, but could in theory be modified to do anything that fits within the scope of an 8-bit computer.
So, after watching these videos religiously and doing some reading on my own, I decided I wanted to build one of my own. I don’t remember why, but for some reason I thought it would be a good idea to build it entirely out of quad-NAND gate ICs, specifically the CD4011B (mostly because they are cheap). This is unrealistic for multiple reasons, which I won’t go into, but I didn’t realize that until I was part-way though building the first component (that I built, not Ben): the ALU.
ALU is an initialism of arithmetic logic unit and is the part of the computer that does all of the math needed for any program. My ALU is about as simple as one can be as it can only add and subtract 8 bit numbers, but as we’ll see even this is pretty complicated when you are doing it with quad-NAND gates.
The first thing to do of course is to design the ALU before it gets built on a breadboard. To be honest, this is probably something that is simple enough that most people could just think about it in their head and wire it up without ever creating a schematic. Recently though, I was interested in learning more about how to use a program called Logisim, which allows you to layout and simulate digital circuits.
Here is the Logisim schematic of the 8-bit ALU, made entirely from 2-input NAND gates:
- Red – inputs. There are two 8-bit inputs for the two numbers that will be operated on, and an toggle for whether we are going to add or subtract.
- Green – eight 1-bit adders. These take two 1-bit numbers and add them together. Each has three inputs and two outputs to account for numbers that are carried in and out.
- Orange – logic for the subtract functionality. There are eight blocks that take perform a 1’s compliment on the B input. The two compliment is then done by adding one to this output using the subtract toggle itself. The three NAND gates on the end handle the carry-out of the most significant adder (in order to only display it when subtract mode is off).
- Blue – outputs. One 8-bit output and one carry.
I didn’t do a write-up detailing how this circuit actually works, because there is already a ton of really good information out there on it. Check out Ben’s video on ALU design to learn more about it.
If you want the Logisim file for this circuit, you can get it from my github page:
So, onto the actual physical design, done on breadboards. Turned out I needed nine total (plus power rails). One each for the adders (and the 1’s compliment logic) and one addition for the I/O and the carry-out logic. Here it is, in all its glory:
I made no attempt to optimize the layout and reduce the number of gates needed. I imagine this could be done with far fewer than what I ended up using, which was 49 (!) quad 2-input NAND gates (CD4011B). I used two 8-DIP switches for the inputs and two single DPDT switches for power on/off and subtract mode on/off. Two sets of 8 LEDs show the two inputs, a set of nine for the output, as well as two additional for the power and subtract mode.
I used a ridiculous amount of 22 AWG solid core wire for this, heavily inspired by the way Ben wired his breadboard computer. Decoupling capacitors are placed on each power rail. If this was clocked and being utilized in a high speed application you would probably need one near every chip.
The boards are powered from a 5V wall wart/transformer. I cut the connector off, stripped the wires, and soldered two sets of headers to them. You can see the IO and LEDs more closely here:
Some of the “custom” components that are used here:
Modified DPDT switches by soldering 0.1″ headers to them so that they fit into the breadboard.
Anytime I needed a wire to connect adjacent pins, I made jumpers by soldering together two 0.1″ headers.
Each of the LEDs has a resistor soldered to it to save space required on the breadboard. A better/cleaner solution probably would have been using SIL resistor packages and bar-graph LEDs.
I think this was a cool project, but my suggestion to anyone who wanted to do something similar would be to take Ben’s advice and pick the level of restrictions you are going to impose on yourself based on what you are trying to learn or accomplish. For example, I wanted to learn more about building an 8-bit computer, and built and ALU with 49 chips when it could be done with 1 or 2. A ton of time went into designing and building, when I could have been learning other things.
Unless your goal is building a NAND-only computer, pick the best IC for the job.