Introduction to Building Computers 🖥️
Before we get our hands dirty with learning how to build a computer, let's talk theory first. In an earlier lesson, we talked about binary and how computers perform calculations. Remember that our computer can only communicate in binary using 1's and 0's. Our computers speak in machine language but we, of course, speak in human languages like English, Spanish, Mandarin, Hindi, you get the idea. If we want to communicate with our machines, we have to have some sort of translation dictionary, just like if I wanted to say something in Spanish, I'd look it up in an English to Spanish dictionary. Well, our computers have a built-in translation book. In this lesson, we'll dive deeper into how our computer translates the information we give it into instructions that it understands.
💻 Programs and Memory
Right now, you're probably using a web browser, music player, text editor, or something else on your computer. We interact with these applications on a daily basis, they're referred to as programs. Programs are basically instructions that tell the computer what to do. We typically store programs on durable media like hard drives. You can think of programs like cooking recipes - we keep these recipes all stored together in a cookbook, just like apps stored on a hard drive.
Now, we want to make a ton of food, so we hire a chef to follow our recipes and whip up something good. The faster our chef works, the more food she'll prepare. The chef is our CPU - she processes the recipes we send her and makes the food. Our chef works super fast, so fast that she can cook faster than she can read. So we take a copy of the recipes and put them into RAM. Remember that RAM is our computer's short-term memory - it stores information in a location our CPU can access faster than it could with our hard drive. Now we can give our chef one or two recipes at a time instead of reciting the entire cookbook to her.
🥪 Instructions in Binary
Okay, now let's say I want to make a peanut butter and jelly sandwich. I see a pretty good recipe and send it to our chef to make. Remember that our chef needs these instructions quickly, so I don't send her the entire recipe. I send her one line at a time:
Get two slices of bread.
Put peanut butter on one slice.
Put jelly on another slice.
Combine the two slices of bread.
📡 Data Transmission and Transistors
Now, let me throw one more thing at you. Our chef can only communicate with us in 1's and 0's. So instead of sending something readable, like the recipe for a peanut butter and jelly sandwich, we have to send something like this:
In reality, this process is a little more complicated. Our CPU is constantly taking instructions and executing them. These instructions are written in binary. But how do they travel around the computer? In our computer, we have something called the external data bus or EDB. It's nothing like a bus at all, it's a row of wires that interconnect the parts of our computer, kind of like the veins in our body. When you send a voltage to one of the wires, we say the state of the wire is "on" and it's represented by a 1. If there's no voltage, then we say that the state is "off" and it's represented by a 0. This is how we send around our 1's and 0's - sound familiar? In the last lesson, we talked about how transistors help us to send voltages. Now we know how our bits physically travel around the computer.
🖧 Memory and Data Storage
The EDB comes in different sizes - a bit, 16-bit, 32-bit, even 64-bit. Can you imagine if you had 64 wires going? You can move around a lot more data. Right now, we're just going to stick with using an EDB with 8-bits in our examples, sending one byte at a time.
Okay, so now our CPU is receiving a byte and it needs to get to work. Inside the CPU, there are components known as registers. They let us store the data that our CPU works with. For example, if our CPU wanted to add two numbers, one number would be stored in register A, another number would be stored in register B, and the result of those two numbers would be stored in register C. Imagine the register is one of our chef's work tables. Since she has a place to work, she can start to cook. To do so,she follows the recipe one step at a time, using the ingredients and utensils on her work table.
⚙️ CPU Instructions and Execution
Now, let's go back to our binary instructions and see how our CPU executes them. Remember the binary representation of the peanut butter and jelly sandwich recipe? Here it is again:
The first thing our CPU does is look at the first few bits to determine what instruction it is. For example, it might see that the first few bits are 00000001
. It consults its instruction manual, a list of all the possible instructions, and finds that 00000001
corresponds to "Get two slices of bread." Great! Our CPU knows what to do.
Next, the CPU moves on to the next instruction and repeats the process. It looks at the bits, consults the instruction manual, and executes the instruction. This continues until all the instructions have been executed.
🔄 Fetch-Decode-Execute Cycle
The process we just described is known as the Fetch-Decode-Execute cycle. Let's break it down:
Fetch: The CPU fetches the next instruction from memory. It knows where to look because it keeps track of the address of the next instruction.
Decode: The CPU decodes the fetched instruction to determine what operation needs to be performed.
Execute: The CPU executes the instruction, performing the necessary calculations or operations.
Repeat: The CPU goes back to the fetch step and repeats the cycle, fetching the next instruction and continuing the process until all instructions have been executed.
🔁 Recap and Conclusion
To recap, we learned that programs are instructions that tell the computer what to do. The CPU is like a chef that executes these instructions. We use binary to represent instructions and send them to the CPU for execution. The CPU follows the Fetch-Decode-Execute cycle, fetching instructions, decoding them, and executing the necessary operations.
Building a computer involves understanding these concepts and assembling the necessary components like the CPU, memory, and storage devices. It's a fascinating process that allows us to harness the power of computing for various applications.
Last updated