God closes one door while opening another window for you. This is exactly me.

I’m CPU. They call me Gump, because I’m a little silly like Forrest Gump.

God gave me a very small brain, with a few registers saving things only temporarily. However, God opened a special window for me: I can run really fast, just like Gump.

How fast is it? Let me put it this way: my work is counted in nanoseconds. I may have made 1,000,000,000 (1 billion) moves in one second of your life.

By comparison, memory is 100 times slower than me, and hard drive millions of times slower than me. Now you get it.

1. Start

I live in a computer case. Every morning, an electric current wakes me up, mixed with a buzzing sound. I know my loyal guard Fan is working again. I’m extremely afraid of heat while my job is to run fast. If I don’t have an electric fan to cool me down, I’ll soon be suffering from heatstroke, and the consequences can get very serious. At that time, my good partners, such as memory, hard drive, network card will all go on a strike. Without me, the system will fall into a dead silence.

I heard that some CPUs work under good welfare policies, which allow them to stay in the dust free data centers with constant temperature and humidity. I am really jealous about that.

Since I only have a small brain, I woke up recalling only a few things that my creator had told me:

1. Your job is to run the instructions.

2. You are not supposed to save instructions. All of your instructions are stored in memory.

3. Your first instruction is at the address 0xFFFFFFF0.

Then just go and get this instruction! I sent the address to the system bus, and the instruction came back quite soon. This was a jump instruction!

I immediately recalled that this was my old friend BIOS waiting for me to run his piles of instructions.

I said to BIOS, “Dude, what are we going to do today?”

“Good morning, Gump.” BIOS never loses his memory and remembers everyone clearly. “It’s all the same. Just a self-test to see if there’s anything wrong with those old guys: memory, hard drives, graphics cards and so on. If there’s a problem, remind the owner with a trumpet.”

I was familiar with these procedures. As usual, there was no problem. I’ve also got something called interrupt vector table done. I knew I’m going to use it later.

When all these things were done, BIOS did tell me, “Gump, INT 0x19.”

I hurried to look up №19 in the newly completed interrupt vector table, and found a lot of instructions corresponding to 0x19.

Then just do it! This batch of instructions moved the first sector of the disk (the first 512 bytes of the disk) to the memory 0x7C00, and I proceeded from here.

I recalled that there would be a bunch of delicate instructions to wake up the confused operating system in the hard drive and carry it into memory.

It’s really complicated here. In order not to bore you into sleep, I deliberately omitted 100,000 words.

You see, that’s why they call me Gump. I do things fast, but I have to be told where to do it, or I’ll just sit there wondering what to do.

2. Run

Once the operating system entered the memory, it became the boss. Everyone has to follow his commands.

I also found myself in a room: progress house.

There was a lot of things in the room, such as process description information package and process control information package. I did not really care about them. I only cared about two important things:

(1) The necessary registers for my work, which were on the workbench in front of me.

(2) Program counter. I used it to remember the address of the next instruction I needed to execute.

“What’s up, Gump.” The operating system was pretty good to me. Every time he was the first to say hello.

“Boss Linux, what’s the job today?” I am always an active worker.

“Come on, run this hello world program!”

The Hello world program was still asleep on the hard drive. I had to load it into the memory first. Otherwise, I could not execute it.

So I picked up the phone to call the hard drive.The phone came to the IO bridge telephone office through the system bus, then transferred to the IO bus, and finally to the hard disk.

I asked him to bring me the data, and then I sat there waiting.

Boss Linux immediately got angry: “Gump, I have told you so many times, why are you still waiting for the hard drive to send you data?”

Yes, I forgot one thing. The hard drive was much slower than me. It only took me 1ns to execute an instruction; but it would take at least 8ms to read the data from the disk. During this time, I could have executed more than 8 million instructions.

I felt deeply guilty. I quickly picked up the phone and called the hard drive: “Brother, use direct memory access (DMA), just as we agreed before. Load the data directly into memory and send a signal to me when you are done.”

“ That’s not bad.” boss Linux was in a better mood.

“Gump, the data hasn’t come yet. Don’t be idle. Here’s a Fibonacci sequence. Come and figure it out.”

“ Fat Espionage sequence? That’s a weird name. Boss, you know, my brain is too small to understand what that means. Can you please switch the process house, set the program counter, and then point to the next instruction? I’ll execute it one by one.” I am not the ambitious type.

“A real Gump!” boss sighed.

My process house immediately changed (of course, boss Linux did it with my help), and the information of all kinds of packages changed, especially registers and program counters.

So I began to calculate this Espionage sequence; but this sequence seemed endless! Some mindless programmer wrote an infinite cycle.

Just then, I received a call saying that the Helloworld data had been loaded into memory and I was asked to process it.

I put down the work in my hand, saved the data, and then went to deal with the Helloworld thing. Data was ready, then I just need to switch to run it.

In fact, the boss did not know that anyone, as long as he/she has run a considerable number of instructions, was able to discover the secrets of these programs.

Although I am a little silly, I did go through “trillion” of instructions. That is to say, I did KNOW something.

And here’s the secret: every program consists of sequences, branches and loops. In fact, branches and loops are like jump to me.

So my job is to call the memory for an instruction, and then execute it. If it is a jump instruction, I will ask the memory for the instruction of the target address. Then I will continue to execute. Life is that simple.

Oh, of course, there is also a complex one: function calls. I have to work closely with the memory to complete that. This is really complicated. Let’s talk about it some other time.

3. New equipment: Cache

Memory is really my best friend. Without him, I can hardly do anything. More importantly, he is much faster than the hard drive. It only takes him about 100 nanoseconds to read the data once. This makes our conversation easier.

He kept telling me, “Gump, I am so lucky to have you here, otherwise I will certainly be bored to death. That hard drive is too slow to talk to!”

“Why is it so slow?” In fact, the memory already told me the answer, but I couldn’t remember it. I had to ask every single time.

“Hard drive is a mechanical thing. A head moves around on a disk that is rotating at a high speed. A simple locating job can take it a long time.”

“Then why does the owner use hard drive?”

“Although it is slow, the hard drive is not afraid of power cut, which would cause amnesia in you and me.”

That’s true. No one can have all the advantages.

Some of my instructions could be completed with my register. However, there were a lot of data needed to be read and written in memory. Though the speed of reading and writing was only 1% of mine, with all instructions stored in memory, I did have difficulty handling that much .

I said to memory, “Dude, can you just work faster?”

Memory said, “Come on, this is already my limit. Find another way out, Gump. I’m telling you, I studied the instructions and data you visited recently, and I found a pattern!”

“What pattern?”

“ For example, after you visit one of my memory locations, you will be visiting it many times later. Also, when a memory location is visited, the nearby location will soon be visited.”

(p.s. It is known as the Local principle of program)

But I already noticed that.

“What’s it for?”

“Since you often visit things located in the same area, why don’t you think about caching them in your place?”

I think it makes sense! Add them to cache!

From then on, every time I read and write instructions and data, I would ask the cache first. Only when cache doesn’t have it will I turn to the memory.

Sure enough, I found it indeed a lot faster due to the existence of the local principle,

4. Self-improvement: Assembly line

Cache makes my work more efficient, which earned me a praise from Boss Linux: “Gump, I think you are getting smarter. You already learned to use cache!”

“I’m not that smart. It’s Memory’s idea. But I learned an important lesson: when you are unable to change others, it’s no use complaining. Just change yourself first.”

“It’s quite philosophical. I hope you can remember it when you restart tomorrow.” Boss Linux laughed at me.

“I’ve found another problem recently, and I’m in an agony! You see, I have four hands: the first hand is responsible for calling to ask for instructions; the second hand translates instructions; the third hand executes; and the fourth hand sometimes has to write the results back to the memory. The problem is, I often find that only one hand is busy while others are idle. You see, when the first hand is busy getting instructions, other hands can only wait. When the second hand is translating instructions, the other three have to wait.”

“I guess we cannot call you Gump from now on. You start to think now.” Boss Linux laughed.

“It is easy to solve. Let me give you an example. Have you ever heard of car washing? Similar to you, people also need to first rinse the car, then spread the cleaner, then scrub, and finally dry the car. But the way they work is different from yours. They work on assembly lines. Think about it: when a car is being dried, there are still three cars in the back. They are being rinsed, cleaned with cleaner and scrubbed respectively. No team will be idle. There are actually four cars in this assembly line. ”

“Why can’t I come up with such a good idea? I can set up an assembly line of my own! Then every hand of mine will be employed.”

People call us high tech. The truth is: all principles hide in our daily life.

With the help of cache and assembly line, I was increasingly efficient now. Everyone was impressed by me. They wanted to give me a new name: superman. But I prefer “Gump”. It sounds more amiable.

I ran instructions meticulously and conscientiously and chatted with my partners from time to time. Soon the day passed, and it was late at night. I knew the time had come to turn off the computer, so I hurried to say goodbye to my partners one by one.

Soon the exciting current disappeared, and the buzzing of the fan was gone. I could no longer make a phone call, and the whole world was silent.

Tomorrow will be a new day!