fbpx

You’ve probably heard that computers only understand zeros and ones. So how does a computer go from zeros and ones to colorful graphical interfaces with buttons and web browsers?

This is part two of two episodes that explain this. This episode is focused on a computer’s microprocessor and how values in memory are sometimes executed as instructions and sometimes used to supply extra information.

Listen to the full episode or read the full transcript below.

Transcript

In part 1 of this episode, you learned all about bytes and memory with a tiny bit of math. Okay maybe a bit more than just a tiny bit. When I was planning these episodes, I realized you probably needed a chance to absorb all of that so I decided to break the topic into 2 parts. What about the microprocessor? Sometimes, I might just call this the processor for short. The microprocessor is what controls and directs everything and it does this by reading instructions one at a time from memory. It doesn’t know how to do anything on its own and relies on the values in memory making sense. Hopefully, you can see why we can’t rely on the random values in RAM to help here. That’s why we need some values to be ready in ROM the moment the computer wakes up and goes to get its first instruction.

Where does it get this instruction?

Well, for our computer, let’s say that the microprocessor has some built-in programming of its own that we can’t get to but that defines its basic behavior. This behavior tells the microprocessor that the very first thing it should do when it wakes up is go to memory address 0 and read that value. We’re going to want the memory addresses 0 through 999 which makes up 1000 addresses to map to our ROM. That way, we can rely on what the microprocessor will find when it looks in memory address 0. We’ll make sure that our computer places the 1000 bytes of RAM right after the ROM. So the RAM will be found in addresses 1000 through 1999.

So what does it find at memory address 0? Well, it had better be the first instruction. The processor will read that instruction and execute it. How does it know what that means? How does it know what to actually do? The same built-in behavior that told it to go to memory address 0 in the first place also knows how to determine what to do. At this level, the types of things the processor will be doing look nothing like windows or web browsers. It takes millions of instructions to build even a small GUI application. It’s a good thing that microprocessors are very good at reading and executing the instructions.

Once the processor executes an instruction, it has more built-in behavior that tells it where to find the next instruction and that will be at the next memory address.

Let’s move away form processors for a moment and talk about instructions in general. Imagine that you’re playing a game with a friend and you can give your friend simple instructions turn left, turn right, jump, and take steps. The other person already knows how to turn left or right and will turn the proper direction by 90 degrees each time. And jump means to jump in place. But what about that other instruction to take steps? How many steps? Let’s limit the number of steps to 5 and let’s also allow 0 steps to mean take no action. Seems simple so far, right? The game will start with you saying “Power Up” and your friend will ask “What’s my first instruction?” We could have you issue the commands in English, but what if we make it a bit more interesting and you issue the commands as numbers. 0 will mean turn left, 1 will mean turn right, 2 will mean to jump, and 3 will mean to take steps. The instruction 3 which is for taking steps will need to be followed by another number for how many steps to take.

You could if you wanted to write out all of your command numbers in order so they will be available without you needing to think about them. Then the number sequence 0 3 1 2 will mean to turn left, take one step and then jump. The important thing to understand here is not so much what the numbers mean but that you need to know where the sequence starts in order for it to have the intended behavior. If your paper gets torn and the first couple numbers 0 and 3 are missing, then your friend will not just miss the first couple instructions but may end up doing completely the wrong things. This is because if we start with the sequence 1 2, then that means turn right and then jump.

What happened? The problem is that when the sequence gets out of order, we can get the instructions confused with the number of steps. In this case, just looking at 1 by itself is not enough to know if that means to turn right or if it means 1 step.

Computers have the same problems. Each value in memory could be an instruction or it could be a piece of data. The only thing that makes something an instruction is if the processor thinks it’s an instruction and tries to execute it.

Some of the memory will be filled with instructions and some will be extra data that the instructions need.

Back to our computer, it knows to start at address 0 and that’s something we’ll need to make sure contains a valid instruction because that’s what the processor expects to find.

Each of these instructions will be small byte sized pieces and that gives us up to 256 instructions to work with. Wait, 256? How did we get 256 when a byte can only count up to 255? Well, 0 is a valid value and when you include 0 the total number of values goes from 0 to 255 which means there are 256 possible values.

The same mechanism that we use to match a particular byte value to some microprocessor instruction is also how we’ll represent things such as English letters, numbers, and punctuation. Let’s take the number 97 and say that means the letter lower case a. Why 97? Why not? We need something and the only really important thing is that we all agree what 97 means. As long as we all agree that 97 means the letter a, then it must be so. The only thing we need to make sure of is that we don’t get it mixed up with an instruction. Because there’s probably an instruction with the value 97 and just like we didn’t want to jump when we intended to step in the game, we also don’t want to multiply when we really were trying to spell a word.

That’s about as simple as we are going to make our computer.

It will start up and begin executing instructions.

These instructions will allow it to rapidly manipulate data and send the results to other memory addresses. Some of these memory addresses will control colors on the screen, some will represent commands that the user is typing, some will represent coordinates that the mouse is currently pointing to.

Putting it all together in a modern computer leads to some instructions that run when the computer first begins. You might not see anything during this stage but some computers will display a logo and maybe play a sound. These instructions will control hard drives and read more instructions and place these instructions into RAM. This becomes your operating system and once it has been loaded into memory, then control passes to it. This is where you’ll see your operating system splash screen and maybe hear another startup sound. The operating system can load other programs the same way. One of these programs could be a web browser.

It’s all just a sequence of byte values though where each value is either an instruction or a piece of data. The only way to tell them apart is to make sure they don’t get mixed up in the first place.