"Who are you?" "My CPU, you were looking at me just now."

"No, I fell asleep!"

I jumped up, opened my eyes suddenly, and planned to pick up the book and read the content of the CPU.

It turned out that my book was gone, and my desk was gone. What the hell, the surroundings are white. Where is this?

There was a young man standing in front of me, picking his nostrils and staring at me, then raised his head and said, "Little brother, what's the point of mechanical reading, just ask, I can answer any questions for you."

"Who are you?"

"My CPU, you were looking at me just now."

I was stunned, and looked carefully. This person was dressed loosely, and he looked lazy and idle. With that hippie smiling face, the overall appearance was a bit wretched.

It was really hard for me to associate this person with the precise calculation of the CPU, and I complained: "If you are a CPU, the calculations are so unreliable."

"This statement is wrong, let alone a person, and a CPU can't be judged by its appearance." The young man raised his hand and reasoned seriously, and then asked: "How do you introduce me?"

I thought about it, also, among those big programmers I know, who are as handsome as me, recognized his identity, and replied: "When it comes to you, I often throw a sentence: CPU is the central The processor, is the brain of the computer."

"Eh..." The young man froze for a moment, "And what's the use of this sentence?"

"It's useless just to be told this sentence, it's just used by laymen to fool children." I also read a little before I realized that if you really want to master programming skills, you have to know how the CPU works, and how it works. It is necessary to know how the instructions and data are saved, who knows how to read a little, and then fell asleep, which is really disappointing.

"How on earth did you interpret the program, run it, and convert it into machine language?" I frowned, eyes full of doubts.

"This is simple. In fact, I am composed of registers, controllers, arithmetic units and clocks." When the young man heard that someone was interested in him, he immediately showed interest: "It is equivalent to my pocket, limbs, brain and clock." They are the same as the heart, so by comparing them, we can get a glimpse of their functions."

register:

暂存指令和数据

"Since it is equivalent to a pocket, it must be used to store things, and what is stored is instructions and data."

Controller:

将指令和数据存入寄存器,并利用运算结果来控制计算机

"How do I carry out data input and data output, relying on these 'limbs' to coordinate data in and out and grasp the overall situation, such as the printing and monitor output that you often use, the input of mouse and keyboard, and the input of memory and disk The output depends on this controller. It does not require any profound skills, but it must ensure the correct execution of instructions and abnormal event handling."

Operator:

读取寄存器的数据

"Now that I have the data and have saved the data, the next step is of course to use my smart 'brain' to perform calculations."

clock:

发出CPU开始工作的时钟信号

"This heart is the source of my 'alive'. When it starts beating, I know I have to work, but some clocks are located outside, providing me with the beating of life from outside the body."

"A simple point division is as follows:"

Seeing that the young man pulled out such a picture from nowhere, I took a closer look. Although the drawing is quite simple, it is clear at a glance, and I also found something.

"Does your connection mean that the controller, arithmetic unit and clock can all be configured manually by controlling the registers?"

"Yes, it can even be considered that our CPU is a collection of registers, but here I must be a little more serious. The internal components of our CPU are many and complex, far more than these four, and these four are the main ones. , These four are also closely related to your programming, so don't carry it with me."

The young man put away the picture, and continued: "You can't make decisions about controllers and arithmetic units, but you can monitor and configure them at all times through registers, because most of them are also registers."

"It's as if in the controller you have:"

Address Register:

AR for short, stores the address of the memory for the CPU to access until the read and write operations of the memory are completed.

Instruction Decoder:

ID for short is to further analyze the instructions into lower-level instructions.

Instruction register:

Referred to as IR, when the CPU wants to execute an instruction, it will first read it from the memory (the address register used to access the memory), first put it into the data buffer register (which will be mentioned later), and then put it into the IR. Finally, the decoding register is interpreted as a micro-instruction operation that is closer to the hardware, and directly controls the hardware action.

Program counter:

PC for short, which stores the address of the next instruction to be executed by the CPU

The young man paused for a moment when he said this, and his tone became a little more serious: "This program counter needs to be paid attention to. This guy not only determines the execution flow of your program, but also the principle of the branching and looping mechanism in your programming. Come on, come on. picture."

As he spoke, he didn't know where to draw a picture.

When I saw how this picture was so familiar, I suddenly woke up, damn it, I just saw it.

"You are very skilled in stealing pictures, but I am familiar with this PC." I waved my hand.

"Oh? Then tell me." The young man touched his chin. Being able to understand and being able to speak are two different things.

I was not polite, and said directly: "The CPU stores data in consecutive addresses, and the program counter is equivalent to the CPU's guide, telling the CPU which address to execute next. When , the value of the program counter will be +1, which is equivalent to telling the CPU address +1, and the CPU will know that the next step should be to execute the instruction at the address +1.”

"Yes, you remember well." The young man nodded affirmatively, and added: "Although each instruction in this picture occupies an address, in fact, when our CPU processes an instruction or data placed on multiple addresses, but the principle of execution is the same.”

And speaking like this, it is natural to know how branch and loop operations are implemented:

Everyone in the programming world knows that this line has three major execution forces, namely sequential execution, branch execution and loop execution.

At the same time, there is such a theorem that no one can break, that is, all operations are completed by sequential execution, branch execution and loop execution.

For sequential execution, the internal principle is naturally that the program counter is continuously +1, and the CPU continues to execute instructions according to the address of +1;

Branch instructions and loop instructions are nothing more than setting the value of the program counter to any value, then the CPU can jump to any address for execution at will, and even return to the address that was executed last time.

For example, the following conditional branch: the address where the program starts to run is 0100, and then the program counter keeps increasing by 1, and when it reaches address 0102, it jumps to address 0104 to execute the instruction content therein. To complete the action of jumping, the jump instruction (JUMP instruction) is used (the part about the instruction will not be expanded here, I am worried that I will go too far.)

 

 

 

"The controller is probably these cases, and the arithmetic unit is next:"

Arithmetic Logic Unit:

ALU for short, responsible for arithmetic and logic operations on data

Cumulative register:

Abbreviated as AC, after the ALU is processed, the result is stored in the AC

Condition Status Register:

Abbreviated as PSW, the status flag and control flag generated after the instruction is completed are placed in this register

Data buffer register:

DR for short, the data read from memory will be temporarily stored in DR

This is what I just said when reading instructions from memory will be placed in this data cache register first, and it is not difficult for me to guess from its name, this must have played some buffer role, "Is it the speed ?"

The young man smiled, "Go on."

"Because I know that the operating frequency of the CPU is much higher than the reading and writing frequency of the memory. If there is such a big difference between the two, there must be a post station for buffering."

"Ha, what you know is pretty good." The young man smiled triumphantly, "Then do you know what single-core and dual-core are?"

"Each CPU has a computing unit embedded in it. This is a single core. Isn't a dual core embedded with two computing units?" Structured.

"What about multi-core?"

"..." I gave him a blank look, is this guy insulting my IQ, "Multi-core is not more than two computing units embedded, you are kidding me."

"Haha, what about hyperthreading?" The young man didn't care, and asked again.

But this question stumped me. I know threads, but what the hell is hyperthreading?

"The world is so big, my little brother still doesn't know enough." The young man shook his head slightly, showing off.

"Don't bullshit, tell me quickly." For new things, I really want to find out.

"Hyper-threading technology is called HT technology, which is to open up more cores without increasing memory resources. You must know that the cycle of our CPU executing instructions is too fast, and most events are idle. The task system allows many programs to continuously switch and execute, making us seem to be executing two programs at the same time, but even so, our CPU is still not fully utilized. At this time, someone will stand up and ask whether the CPU can be executed at the same time in a true sense. There are two programs."

"The HT technology came out soon, and the mechanism is to divide the CPU's register resources into two, and then use them for two groups of programs. This time, instead of using the method of multi-tasking allocation, these two groups of programs use the CPU's operations at the same time. Unit. So when you have the opportunity to detect the CPU core in the future, you will find that although the CPU is nominally n-core, but the detection has 2n cores, there is no doubt that it uses hyper-threading technology, which can logically run at the same time 2n programs."

"Oh." I suddenly realized, I didn't expect this kind of thing to exist, the world is really big.

""The last is the most important register for programmers. There are too many of these guys, but they can be divided into eight categories in terms of types:"

Accumulation register:

Store the calculated data

Flag register:

Store the state of the CPU after the operation (such as positive, negative, zero, storage overflow, parity, etc.)

Program counter: This we just discussed.

Store the memory address where the next instruction is located, which determines the flow of the program

Instruction register: We seem to have discussed this just now.

Storage instructions, this part is for internal processing by the CPU, and the programmer cannot operate

Stack register: Ours just now seems to be... oh, I didn't say it.

The starting address of the storage stack area

Base address register: Complementary to the following register.

The starting address of the storage data memory

Index register: Do you still remember the address register that stores the accessed memory address just mentioned? The two should be distinguished and not confused.

store relative address relative to base register

General registers:

store arbitrary data

"Among the above eight types of registers, only base registers, index registers and general registers can have more than one, and the other five registers have only one."

"Okay, roughly the internal environment of the CPU is that much." The young man exhaled, looking much more relaxed.

But my doubts have not been reduced because of this. After sorting it out, I found a problem, "You have lost so many things about the CPU, but what does this CPU look like?"

"Don't worry about this. You can't see the CPU. What you can see in the market is the combination of CPU and memory. According to you, it is IC. I found two selfies of IC brothers. You'll understand when you read it."

"You two brothers look quite unique." I almost laughed out loud, thinking that he would show something, but this also made my brain clear all of a sudden, the CPU has always been just an abstract existence , Now I finally have a frame in my mind.

"Then you two brothers, which one has better performance? It should be brother No. 2, I think there are quite a lot of stitches." I rubbed my head and asked again.

"That's right, but in terms of performance, it's not accurate to just look at the number of pins. It should be judged from the following three aspects and Xining:"

1. Instruction set

There are instruction sets inside the CPU, and different instruction sets will affect the working efficiency of the CPU.

Second, the CPU frequency, that is, the main frequency

First of all, we must clearly know what frequency is, that is, how many times the CPU can perform work in one second. For example, a CPU frequency of 3.6GHZ means that it can perform 3.6 * 10^9 work in one second.

Of course, the above is the internal frequency of the CPU. Since there is an internal frequency, there will naturally be an external frequency, and the speed at which the CPU communicates with external components is called the external frequency.

In addition, it also involves a concept - frequency multiplication, frequency multiplication is the multiple of the internal adjustment frequency of the CPU, so multiplying the FSB and the frequency multiplication is the main frequency of the CPU.

"Of course, some installers like to manually set the frequency multiplier to exceed the maximum frequency multiplier, which is overclocking. Although the CPU frequency and FSB will be increased, but because the overclocking is not a normal speed, I can't remember how many times I have gone."

"But fortunately, today's CPU will actively overclock according to the computer's usage, which makes my work pressure much easier."

3. CPU bit width

"I don't know how much you understand about memory, but here you only need to know that all the data of the CPU comes from memory."

That being the case, the greater the amount of data that the CPU can fetch from memory each time, the better the performance will be. Therefore, there is the concept of "bit width". The bit width is how many bits of data the CPU can fetch from the memory each time it works. Currently, there are 8 bits, 32 bits, and 64 bits.

"That is, the above three judgments need to be combined. You can neither judge the performance level simply by the instruction set, nor can you judge the performance level only by the CPU frequency, let alone think that the higher the bit width, the better the performance. Everything must be combined with actual needs. and actual implementation.”

"Tsk tsk tsk." After listening to it, I couldn't help clicking my tongue. It turns out that there are so many ways here, and today's harvest is not bad.

"Ding~"

"Yo, it's time, it's time to go." The young man looked at his wrist without a watch.

"Ah? What time, are you leaving? Come on, tell me more." I was still immersed in digesting the information I just heard, and when I heard that he was leaving, I felt a little depressed.

"I'm afraid this won't work, but you can contact me next time if you need it." Then he handed me a piece of paper, "There is my contact information on it. Welcome to visit me next time."

"Sponsorship?" I didn't understand what this meant, so I quickly looked at the note, and it turned out to be a bill, which clearly stated: The total amount of consultation fees is xxx heaven coins.

Fuck, when will I have to pay for consultation, what the hell is this Paradise Coin?

"Nima..." I just wanted to say hello, but I raised my hand to see that no one was there. Recalling the way he answered me so enthusiastically just now, I couldn't help but sigh with emotion:

The whole TM is a routine.

Guess you like

Origin blog.csdn.net/weixin_41904238/article/details/104931594