📜 ⬆️ ⬇️

How CPU works: an interactive tutorial for beginners

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 is intended for “the smallest,” even an educated person is pleased to see how accessible and elegantly the complex material can be expounded.

The lesson consists of 8 interactive examples.

1. Binary numeration .
')
2. Logical operations using the example of a Scheffer stroke (NAND gate).


Schaeffer Bar (NAND gate)

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


D-trigger (delay trigger)

Eight triggers save 1 byte of information.

4. Logical operations AND, OR, XOR . By clicking on the incoming values, you can clearly see how they work.



What to do with the numbers that we store in memory?

5. The diagram shows a device called an adder that adds two bits. If you need to add several 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 scheme.

Further, how to make a computer out of a calculator?

6. Programming .

From the point of view of the CPU, the program does not differ from the data in the sense that there is the same binary code. But he is perceived as instructions . For example:

InstructionCode
"Add one number to another"00000001
"Subtract one number from another"00000010

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

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

00000001 00000101 00000111
(add) (address number 5) (address number 7)

7. CPU instruction set .

8. Emulator CPU .

Here the author suggests playing with a simple processor emulator, specifying the instructions in separate memory cells. In this case, the instructions change the value of other cells, where instructions are also stored. You can come up with funny recursions. The computer understands three instructions: addition, subtraction and movement of data from one cell to another.

Simple CPU on Github

about the author
PS It is interesting that the project was born on the Reddit forums , and its author is r00nk, who just finished school. Since r00nk is a bad student, it is not taken at any good college right now, so he is trying to complete a computer science course on his own, while at the same time studying OpenGL.

Source: https://habr.com/ru/post/240929/


All Articles