Back to Home

How the CPU works: an interactive lesson for beginners

Simple CPU · CPU · binary numbering · Scheffer stroke · NAND gate · D-trigger · instruction set

How the CPU works: an interactive lesson for beginners

  • Tutorial
Simple CPU is a small lesson that introduces the beginner to the key concepts of computer science. Although the lesson is far from complete and intended for the “smallest”, even an educated person is pleased to see how difficult and sophisticated material can be presented.

The lesson consists of 8 interactive examples.

1. Binary numbering .

2. Logical operations by the example of the Schaeffer stroke (NAND gate).


Schaeffer Bar (NAND gate)

3. Trigger . Demonstrates how information is stored on a computer. The upper switch changes the value of the bit, and the lower enables / disables storage.


D-trigger (delay trigger)

Eight triggers store 1 byte of information.

4.Logical operations AND, OR, XOR . By clicking on the input values, you can visually see how they work. What to do with the numbers we keep in mind? 5. The diagram shows a device called an adder that adds two bits. If you need to add a few bits, then several adders are used sequentially: the input of one (carry in) is connected to the output of the other (carry out). Again, this is an interactive diagram. Next, how to make a computer from a calculator? 6. Programming . From the point of view of the CPU, the program does not differ from the data in the sense that here is the same binary code. But it is perceived as instructions . For instance:

















Instruction manualThe code
"Add one number to another"  00000001
Subtract one number from another  00000010

Each byte in memory has its own address, so we can turn to the CPU and ask to do something with a specific byte. For example, if you need to refer to memory cell No. 5, we indicate its address 00000101.

Thus, the command “Add the number in memory cell No. 5 with the number in memory cell No. 7 is translated into machine code:

00000001 00000101 00000111
(add) (address) No. 5) (Address No. 7)

7. Set of CPU instructions .

8. CPU emulator .

Here, the author suggests playing around with a simple processor emulator, indicating instructions in separate memory cells. At the same time, instructions change the value of other cells, where instructions are also stored. You can come up with funny recursions. The computer understands three instructions: adding, subtracting, and moving data from one cell to another.

Simple CPU on Github

about the author
PS Interestingly, the project was born on the Reddit forums , and its author is the user r00nk who just graduated from school . Since r00nk is a doppelgänger, he is not currently admitted to any good college, so he is trying to take an informatics course on his own, while studying OpenGL.

Read Next