One of the most important parts of any CPU is the Arithmetic – Logic Unit or ALU, because it’s responsible for performing computations. We need to understand where data is stored in order to have a better idea about how this process works.
Let’s say we have an equation written on paper that looks like this: 2 + 3 = 5. The way that our brains solve this problem is by moving two 3s from one side of an equals sign to the other, which leaves us with 5 on both sides. This wouldn’t work if there were more numbers involved, but it gives us an idea about what’s happening at a high level.
A computer can do something similar, but instead of having to move numbers, it has to be able to access locations in memory. Imagine for a moment that the computer’s RAM is like an Excel spreadsheet where cells A1 through D10 are all empty. We can give each cell a number (A1 == 1; B2 = 2; etc.) and let the computer know which row or column we’re talking about by using those numbers as well.
It’s now time to figure out what happens when you type something into Microsoft Word. You probably have seen the little blinking cursor after typing something, so let’s say that point goes somewhere between cells A4 and C5. The next step is figuring out what happens when you hit enter on your keyboard, which tells Word that you want to start a new line.
When you hit enter, Word moves the blinking cursor down one row and puts it somewhere between cells A5 and C6. The exact location will depend on how many letters were already in those cells as well as any punctuation marks that were present. This is why hitting backspace sometimes deletes entire words instead of just one character – because there’s a big blank space where a word used to be! Now for the moment you’ve all been waiting for –
What actually happens when you type numbers into Word?
If we remember that the computer sees memory as a spreadsheet, then we can understand that it will treat each number as if they’re actually values in their own little Excel cells. The computer will store the number in memory and then compare it to the previous location just like how Excel would.
This means that if you type 2 into cell A4, then that’s where Word will put it. The only problem is that there’s nothing in B4 or C4. To solve this problem, we need to tell Word what we want those blank cells to be filled with before we start typing numbers – and this requires something called a Data Type .
There are four different types of data:
Text data (anything you can type on your keyboard), logical values (things like True and False), integers (the positive and negative whole numbers such as 0, -2, 4, 7387578757875, etc.), and real or floating-point values (numbers with decimal points such as 1.0, 742.1234, -1.2345e+7).
Real numbers are important because they’re the only way that the entire concept of a number can work. Without them, we would have to limit all numbers to whole integers which would make it impossible to calculate things like square roots on a calculator for example. Our iPhones can do this because they use real numbers in order to represent locations within memory where the results will be stored.
Let’s say you want your phone to take the square root of 498323520356464 = 1446.1917241110928. It will first have to set up a few variables so it knows what you’re talking about. First, it sets one variable to 498323520356464, which is the value that we want the square root of. The only problem with this is that computer memory doesn’t actually contain numbers – just zeroes and ones.
In order for our computers to actually deal with these values as numbers, they have to calculate where those zeroes and ones are stored into regular integers called binary numbers. If we were to take a regular number such as 1,234,567 and write it in binary form (110001001100101), then each column represents 8 bits of data because there are 8 digits in our regular number.
Let’s go back to when we were getting ready to type in 1446.1917241110928 into our calculator app. Instead of typing in the real value, let’s say that we typed it in as 448. Our phone would take the square root of 498323520356464 and then store that result into another variable which will be called “y”.
This means that the first column (the left-most one) in our memory will contain 8 zeroes because there are 8 digits in 458. The second column will be filled with 8 ones because 4 + 8 = 12. The third column will be filled with 7 twos and so on and so forth until all columns are filled up. Once all of the columns are filled up, our phone stores the result into “y” which would be 1446.
This process is similar to how Excel works with cells A1 through J1048576 instead of using regular numbers that go from 0-255. If you ever wanted to know what happens behind the scenes when you hit = SQRT (498… on your calculator app, then this might give you some insight as to how it actually does it). Now let’s look at why memory is so important!
Since we now understand how functions work in memory, we can actually use them to do things like move locations around so that they’re easier us humans to remember. Let’s start this up by telling you about the goto command.
The goto command allows us to create labels that we can then jump to when needed. These labels are just words that we define and give a name (for example: GoToSquareRoot). If we wanted to take our square root example from earlier and make it go straight to the result, all we would have to do is put GoToSquareRoot right before storing the value in “y”.
This works because we told our phone where square root was (in memory) and now square root will know where to find its own results (also in memory). What does this mean for us? Well, if you play games or use full-scale programs such as Microsoft Office, then it’s likely that the codes to run these applications are stored within memory. This isn’t just for high tech programs either – even Angry Birds gets stored in memory when you play it!
Now that we know what happens when an application runs, how does computer storage work? Let’s talk about hard drives. I’m sure most of us have heard of them before and most of us probably understand how they work on a very basic level.