Post

Building a 4-bit CPU with integrated circuits and breadbords

A few weeks ago, while packing for a move, I stumbled upon an old 4-bit CPU that a friend and I built during our first year of college. For our “Computer System Architecture” class, they didn’t give us specific instructions—just that it had to relate to the course topics. My friend and I were fascinated by the inner workings of a CPU and eager to understand how it actually functions. We were learning about Boolean logic, the architecture of a 4x3 RAM chip, and the simplified instruction set of an Intel Pentium chip, but none of this really explained how transistors and logic gates come together to create such a complex piece of engineering like a CPU.

Around that time, electronics engineer and YouTuber Ben Eater posted his first couple of videos on building an 8-bit CPU with integrated circuits and breadboards. The initial videos only covered building a proper clock, but that was enough to hook us. We decided to build our own CPU for the assignment, even though we knew Ben Eater’s series wouldn’t be finished before our deadline.

Here’s a quick video of what the end result looked like:

The Arduino only serves as a 5V power source

Building the CPU

We started by ordering a bunch of integrated circuits from Texas Instruments, since we couldn’t find any in Uruguay. These circuits were supposed to help us build the clock. To our surprise, the integrated circuits didn’t fit in the breadboard—they were five times smaller than the ones we needed (yeah, and five times smaller than what they showed in the pictures 😐).

mad gif

After visiting every electronics shop in Uruguay, we finally found a small, old shop that sold the type of chips we needed.

Clock

You might think it would have been smooth sailing from there, but unsurprisingly, they didn’t have the exact models we needed. 🤦‍♂️ The interesting part is, this actually led to our first big lesson: you don’t need to copy every step and use the exact materials; you can use what you have and think your way through it. The integrated circuits we bought served the same purpose, but since they were a different model, each pin had a different function. This forced us to read through each chip’s documentation instead of blindly following Ben’s videos (which we did try at first).

A couple of days in, and we had our clock working! I’m not going to dive into the implementation details for the clock because, first of all, I don’t remember everything about it 😂, and more importantly, knowing the internals doesn’t contribute much to fully understanding how a CPU works. As long as you know that the clock provides regular energy pulses to the rest of the CPU every few milliseconds (each pulse being a clock cycle), and that an operation is executed in each cycle, you should be fine.

We’ll dive into the “operations” that the CPU executes later in the post. Meanwhile if you’re curious about the internals of a CPU clock, you can watch this video from Ben Eater.

ALU, Registers and a simple BUS

After building the clock, we moved on to the ALU and the registers. The ALU (Arithmetic Logic Unit) is the part of the CPU that performs arithmetic and logical operations, while the registers are memory units that store the data the ALU operates on.

This is where we decided to make our CPU a 4-bit CPU. The old store had limited chip options, and we couldn’t afford to order new ones from Texas Instruments without knowing if they would be suitable. We could have chained 4-bit registers and ALUs to create an 8-bit CPU, but we opted to keep things simple and start small, knowing we could always expand later.

Here are some key insights we gained while building the ALU and the registers:

  • Register Control: You can control when to load data into a register by changing the voltage of a pin. This was our first glimpse into how you can actively manage the flow of data in a CPU, demonstrating that loading data from the BUS isn’t just some magical, automatic process.

  • ALU Operations: For the ALU, you can dictate the operation it performs by altering the voltage of a specific pin. Our simple 4-bit ALU could only handle addition and subtraction, controlled by the voltage at a single pin. If it supported more operations, additional pins would be involved.

  • BUS Functionality: Data can also be output from the registers and ALU to the BUS. Here, we realized that the BUS acts like the CPU’s highway, connecting various components that can read from and output data to it.

After assembling the ALU and the registers, we set them up so that the ALU would output results to the BUS, and register A would read the data from it, enabling us to perform multiplication tables!

RAM

The last component we managed to assemble, which isn’t featured in the video, was the RAM. It comprised several small RAM chips, each capable of holding 4 bits of data. We manually loaded data into these chips using DIP switches.

While the RAM itself might not seem particularly exciting, it’s important to understand its function in a CPU system. RAM is used to store the results of operations performed by the ALU as well as the instructions that the CPU executes. This makes it a critical component, serving as the storage and retrieval point for both data and operational commands.

CU, where the magic happens

The last piece of the puzzle was the CU (Control Unit). Although we attempted to build it, we ran out of time and didn’t have a detailed guide or tutorial to follow, as Ben’s series was only beginning to explore the ALU when we reached this stage.

The CU is where terms like “Instructions,” “Machine Code,” and “Assembly” transition from abstract concepts into practical components of computing. Recall our earlier discussion about the Registers, ALU, and BUS? The CU is responsible for controlling the voltage of specific pins to manage the loading and outputting of data to and from the BUS. This central role in coordinating how the CPU processes instructions makes the CU a fundamental element where much of the computational ‘magic’ occurs.

But how does it do it?

The CU connects to every “control” pin, thus controlling the operations of the ALU, including whether registers should load data from the BUS. This is where you define your CPU’s instruction set. For example, “0001” might be set to instruct the CPU to “load data from the BUS into Register A,” triggering the appropriate voltage change in the register’s control pin to perform the operation. Similarly, “0010” or another binary code could be assigned for different instructions.

This variability is why there are many different Assembly languages, as their instruction sets are defined arbitrarily based on each CPU’s architecture.

By encoding your instruction set in an EEPROM, the CU is programmed to deliver specific control signals to other components based on the instruction codes it receives (“0000”, “0001”, etc.). This is crucial for directing the precise behavior of the CPU during each operation.

Now, the CU receives instructions from the same BUS that supplies data to other components. In a 4-bit CPU, the limited number of bits presents a challenge: ideally, you use all bits for data or instructions at different times, rather than permanently dividing the bus. Implementing a strict division (2 bits for data, 2 for instructions) severely restricts operational flexibility, limiting you to just 4 distinct operations.

At this point, we decided to conclude our project. While most of our peers had only built simple systems using Arduinos and sensors, we believed our project would earn a good grade. More importantly, we had gained a deep understanding of how a CPU works, satisfying our curiosity.

Conclusion

If you’re an electronics engineer, you might find this post a bit basic or lacking in detail—and that’s exactly the intention. As software engineers, we rarely get a firsthand look at the hardware we work on. Peeling back some of the “magic” behind a CPU is a fantastic way to spark curiosity and encourage others to explore this fascinating subject further.

I definitely recommend watching Ben Eater’s complete series. After our assignment was done, I watched it to see how he addressed the issues with the CU that we couldn’t figure out. Let me tell you, he is a genius. If you’re interested, you can check out his series here.

This post is licensed under CC BY 4.0 by the author.