As we all know, the CPU is the central processing unit, which is the control processing center. Our computers, mobile phones and other electronic products are inseparable from the CPU. So, how exactly does the CPU internals work? Let’s take a look together.

1. When we work hard with the computer, we do not know that the computer is also working hard.

When we open the case, we will see the motherboard of the computer, and we can also see that the fan is constantly rotating. Below the fan is the CPU, which is constantly communicating with the memory, just like our brain. The CPU is composed of many many transistors, mainly including controllers, arithmetic units, and registers. The registers are divided into digital registers, instruction registers, and instruction address registers. Suppose there are four digital registers, which can hold temporary data. On the right is the memory, and there are 16 storage locations, each with 8 bits.

2. How exactly does 2CPU and memory work?

When we start the computer, all registers start at zero. Assuming that the memory stores a simple computer program, the first stage of CPU operation is “instruction fetch”, which is the process of obtaining the first instruction.

First, the specified address register is connected to the memory, and the value of the register is zero. Memory returns the value 00101110 at address 0. The value is copied into the specified register, and then the CPU begins to parse the instruction in order to perform what kind of operation. This step is called “decoding”.

The first four digits of the designation are the operation code, and the last four digits are the operation code. Where does it come from? Since the first four bits are the operation code 0010, corresponding to our instruction set, 0010 is to read the memory and put it into register A, and the last four bits are the address 1110 of the memory. That is the number 14 in decimal.

Next, use some logic gate circuits to check whether the opcode matches 0010, and the output is 1, indicating that the match is successful. Next, the instruction is executed, that is, the execution process.

Check the circuit output through the logic gate circuit, open the read line of the memory, find the address 14 of the memory 1110, read the value of the address 00000011, next store the value in register A, we connect to the 4 numbers through the data line Register, the CPU opens the data register A through the instruction to allow writing. The data is written into register A and we have completed the instruction.

Now turn off all the wires and get ready to read the next instruction from memory. The instruction address is incremented by 1, and the memory returns the value 00011111 at address 1, which is copied to the instruction register. Then to the decoding process, through the specified set, specify the first four bits 0001, which means that the read memory is stored in register B, this time the memory address is 1111, and the corresponding decimal mantissa is 15. In the execution process, open the memory read line, Find the memory address 15 and read the value of this address. And store the value 00001110 in register B through the data line, and finally increase the specified address register by 1, and close all lines.

Now the value 10000100 of the memory return address 2 is put into the instruction register. The CPU starts decoding from the specified set, and the opcode 1000 is the addition instruction. Add two registers and store them in the second memory. There are two kinds of designation. The first two bits of 01 correspond to register B, and the last two bits of 00 correspond to register A. Therefore, 10000100 means that the value in register B is added to register A.

Connect the registers A and B to the input of the operator, the operator performs the addition operation, and the result of closing the output of the operator is stored in the register A. 00010001 means that the input value is the sum of the two values ​​3 and 14 equal to 17, then the specified address is increased by 1, and the process is completed to find the value of memory address 3.

We open the instruction set to start decoding, 0100 means read the A register to the memory, 1101 corresponds to the memory address 13, and then send the value of register A to the address of memory 13 through the data line.

3. The program of the computer we just ran, it loads two values ​​from memory and adds them, and then puts the result into memory, that is, the CPU’s instruction fetching, decoding, and execution process. Our computer system is composed of many, many small programs, and the CPU is constantly cycling this process.

Each CPU performs this process at a different speed. This speed is determined by the main frequency of the CPU, that is, the operating frequency of the CPU, which determines the speed of the CPU.