How a Processor (CPU) works

Motivation

If we boil down to the basics, a software programmer basically writes a set of instructions for a processor to execute. Implicitly, a software programmer is expected to know how a processor works in general.

However, high level programming languages such as Python, Java etc. have abstracted a lot of rudimentary operations of a processor. Rightly so, higher level abstractions have had a positive effect on the programmer productivity. For example, to make computer print a simple message on a monitor, is a one liner in the Python programming language.

print “Hello World!”

This is awesome! However, at the processor level, which only understands high or low voltages, is not that simple. Agreed!

But why go down to the nitty-gritty details of how a processor works when the high level languages make your work so much easier. Well, in my view, I think these are following reasons, which motivate to seek the understanding of processor.

  • You’re limited by the functionality provided by a given programming language.
  • By knowing how a processor works, you might develop a solution optimized for a particular processor.
  • Also, it would equip to ask the right kind of questions. It would be act as starting point for you to ask how a processor in your smart-phone, computer or raspberry pi work, or even estimate or compare the performance of different processors.

Prerequisite Knowledge

Computer Science 101.

Or

Programmed a computer using any programming language.

Processor In Action

Without further ado, let’s jump in. Fasten you’re seat belts. It’s gonna be an interesting ride.

If that was too much to take, you shouldn’t worry. I also had to go through video twice or thrice to fully grasp the concepts.

Interactive Processor Model

That was the theory, now for some practice. There’s an awesome, interactive, computer simulator created by Marco Schweighauser. In this interactive tool, you can write instructions and make them run. The tool shows how the processor loads and manipulates information.

Initially, the default program might a bit too much to follow. You can replace all the code with a single instruction such as:

MOV A, 10

and click assemble. You can see how your instruction was loaded into the memory. Then, you can click RUN to see how your values are stored in the CPU registers.

Once, you grasp hold of these basic commands, you can try and see how the default code works (reload the website).

Have fun ☺

Questions

I believe this article has served to stimulate your mind to ask questions to the general observations in every day life, at-least in the field of computers. You might as well question such as how does the CPU communicate with the keyboard (or any input device), monitor (or any output device), storage devices (such as SSD), printer or with the other computers (the Internet).

These days, even smart-phones have multi-core processors. How do they work? Are they different from desktop processors? How can I check how many cores my computing system has? What’s hyper-threading? How can I write my programs to use all the cores to achieve maximum performance? These are good questions and they require critical thinking and time to answer. I believe you can attempt to answer them.

Boy that was too much to take in one sitting. You should get a break, reward yourself with food, sex or play games such as agar.io.

If you have any questions, criticism, comments or suggestions, feel free to let me know.

Next Section

In modern computers, an operating system (OS) is generally running. We will see how an OS boots in general.