Learn to make a simple CPU in the first semester

A general talk about how to make a processing and memory unit in CPU. Learned @ Imperial.

It’s not a paramount task. Everything is just messy but elegant.

Imperial is teaching contents worth 2 years of studying in the first two semesters, so it doesn’t surprise me when I finally know how a CPU(Central Processing Unit) works. However, to understand the essence of the bigger parts, we have to look at simple gates and design patterns. Down to the earth, the logic gates are sea of math and physics. We are given the building blocks, only puzzled at what to do with them.

To start with, we have several basic units that we can deploy:

The details of those logic gates are in this site. In short, the three basic ones are not, or, and. Other gates are just the derivatives of those three. The buffer returns the input directly as output. It is used to increase propagation delay and amplify signals.

Some interesting things can be built using those basic gates. For instance, we can build a 2-input multiplexer using one not gate with two and gates, one or gate.

When X = 1, the output is B; when X = 0, the output is A. So the multiplier is just a selector for several input signals. Similarly, we can built multiplexers of any size with increasing size of selecting bits. For instance, a 4-input selector needs two selecting bits. In the order of S2S1, 00 for A, 01 for B, 10 for C, and 11 for D.

We can also build a decoder, which might be considered as the reverse of what multiplexer does. Instead of choose one output from several input, a decoder chooses a signal as the input towards some other structure connecting to it.

Those are really useful in terms of controlling signals. We will later see how those things play a critical role in a central processing unit.

Taking things to the next level, we now illustrate how a develop a circuit based on truth table.

First, let’s say we are developing a full adder. By the addition rule, 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, 1 + 1 = 0. Because we need to take the carry-in from the last digit as well, so there is actually three inputs: A, B, and Cin. The truth table is shown below:

Next, we draw Karnaugh map for both Sum and Cout. (a) is the k-map for Sum and (b) is the k-map for Cout.

We then generate the minterm or maxterm formula. Minterm formula is in disjunctive normal form, while maxterm formula is in conjunctive normal form. From the K-map above, we can generate the minterm equations:

SUM = (A XOR B) XOR Cin = (A ⊕ B) ⊕ Cin
Cout = A AND B OR Cin(A XOR B) = A • B + Cin • (A ⊕ B)

Full Adder Circuit

In the similar fashion, we can design subtract or, multiplier and division hardwares. Those can be used in basic operations in a central processing unit. If you want to know more about how to use truth table and K-map to develop a circuit, go visit this site.

Here, the multiplexer can be of great use. For instance, you can choose from different operations using a 4-input multiplexer. There are two different sorts of operations: and, or, not, etc are called logic operations, whereas addition, subtraction and multiplication are called arithmetic operations. In a professor, those two sorts are implemented in a single unit called Arithmetic Logic Unit(ALU).

A simple ALU unit

Other parts of a CPU can be built in a similar fashion, only differs in details and optimizations.

There is another kind of circuit that is dedicated to build memories: flipflops.

A simple SR flip flop using NAND gates

Flip flops can be used to make memories. We know that for AND/NAND gates, if one of the input is 0, then the output can be determined since 0 AND anything produces 0. Based on this fact, we can generate truth table and the state of the flip flop:

There are two configurations that can remember

We can see that this can work as a memory because when S = 0, R = 1, Q is set to 1 and stay that way; when S = 1, R = 0, Q is reset to 0 and stay that way. Essentially, we call it Set-Reset flip flop. This is an example of memory. What many people called register is made up by thousands/millions of flip flops. There are other types of flip flops, but all of which are founded upon the idea of a single SR-flipflop.

Using flipflops allows us to make combinational circuit, but we will not go further here. Put it simple: combination all circuit allows you to make controllers that switches between different states(e.g. Signal lights).

All the things above are just standard class content for the first year of electronic engineer or computer engineer major in a typical college/university. If you wish to learn more, go to read more in this book.

Leave a Reply

Your email address will not be published. Required fields are marked *