Storage Devices
Binary patterns encode machine language instructions and data.
Why a Stored Program Cannot Run Straight Away
When you think of a computer running a program, it is tempting to picture the processor reading instructions directly from wherever the program lives. In practice a computer keeps its information in more than one place, and each place has a different job. A hard disk or solid state drive can hold programs and data files for a long time, while the processor itself works with a separate part of the machine called main memory. Understanding how these pieces fit together is the first step toward understanding what a computer does when it runs anything at all.
What do you think happens?
Can the CPU run a program directly from a hard disk, or must the program go somewhere else first?
Reveal answer
The program must first be loaded into main memory before the CPU can execute it.
A program stored on a hard disk or solid state drive has to be loaded into main memory before execution. The CPU fetches and executes the instructions that are held in main memory.
Following a Program from Disk to Processor
Tracing a program is a useful way to see the separation of roles in action. The route has two different purposes. Storage devices keep larger amounts of information permanently, so a program or data file remains there even when the computer is switched off. Main memory holds the machine language programs and data that the CPU needs during execution. It holds a comparatively small amount, and it keeps that information only while power is on. Because of this difference, a program has to be copied from storage into main memory before the CPU can run it. The diagram below shows that route as a sequence of movements.
Starting a Word Processor from a Hard Disk
A word processor program is stored on a hard disk. Trace where its instructions go when the user starts it, and state where the CPU reads them from during execution.
- 1Program at rest
While the computer is off or the program is not running, the program sits on the hard disk as stored information. The disk keeps it permanently.
- 2Loading into main memory
Before the program can execute, it is copied from the disk into main memory. This step is required because the CPU executes instructions held in main memory.
- 3Execution by the CPU
The CPU fetches the instructions from main memory and executes them. The disk is not the place the CPU reads from during execution.
- 4What happens at power-off
Main memory keeps its contents only while power is on. The program remains safe on the disk, so it can be loaded again the next time it is started.
The program travels disk to main memory to CPU. It is stored permanently on the disk, executed from main memory, and reloaded from the disk when needed again.
Binary Patterns as Instructions and Data
Everything in the route above is made of the same raw material: binary. Computer instructions and data are encoded as binary numbers, which means as patterns of 1s and 0s. Binary can be represented by switches, where on corresponds to 1 and off corresponds to 0. A stored pattern is therefore a row of switch settings. When an instruction reaches the CPU, the CPU responds to the pattern because of how its internal switches are wired together. The same kind of binary encoding carries both the instructions the CPU executes and the data those instructions work on.
A machine language instruction is not a special kind of object separate from numbers. It is a binary pattern. Whether a stretch of memory is treated as an instruction or as data depends on how the CPU is working with it, and the bits themselves are the same kind of 1s and 0s either way.
Reading a Memory Layout of Bit Patterns
Main memory can be pictured as a row of cells, each holding a binary pattern. The diagram below shows four cells in order. The patterns are illustrative only and do not represent any particular instruction. Its purpose is to make the idea concrete: a cell holds bits, and the CPU works with those bits as it executes a program that has been loaded.
How the CPU and Main Memory Work Together
Once a program is in main memory, the CPU and main memory form the central execution pair. The CPU fetches instructions held in main memory and executes them. The data the program works with is also held in main memory, which is why the loading step described earlier matters. The CPU does not run the program from the storage device; it depends on the copy that has been placed in main memory. Keep in mind that this pair is the core of execution, not the whole computer. Other devices are part of a complete system, and they become relevant when they are involved in an activity.
Why Storage Sits Outside the Execution Pair
A computer needs storage devices and main memory because they are designed to do different jobs. Storage devices provide permanent storage for larger amounts of information. Main memory is volatile and comparatively limited, but it is the place where the CPU can work with the program during execution. The comparison below summarizes the differences the source material describes.
| Feature | Storage device | Main memory |
|---|---|---|
| Permanence | Keeps information permanently | Keeps information only while power is on |
| Volatility | Non-volatile | Volatile |
| Amount held | Larger amounts of information | Comparatively small amount |
| Role in execution | Holds programs and data files until they are loaded | Holds the programs and data the CPU executes |
| Examples given in the source | Hard disk (spinning magnetic disk) and solid state drive (electronic, no moving parts) | Main memory as described in the lesson |
Storage devices and main memory serve different purposes in one computer.
The two examples of storage given in the source differ in how they are built. A hard disk stores data on a spinning magnetic disk. A solid state drive is purely electronic and has no moving parts. Both can keep larger amounts of information permanently, which is the property that main memory lacks.
Asynchronous Events and Devices Outside the CPU
The word asynchronous describes events in this lesson that involve a device outside the CPU and main memory pair. A complete computer also includes other devices, and a hard disk or solid state drive is an example. When activity involves such a device, it belongs to the asynchronous-events topic. The key point is that the storage device is not part of the central execution pair, so an action that involves it is handled as an event that sits outside the CPU and main memory.
Mistakes Beginners Make
Common mistake Believing the CPU runs programs directly from the hard disk or solid state drive
What it looks likeAssuming a program stored on the disk can be executed without any copying.
Why it failsPrograms stored on a hard disk or solid state drive must be loaded into main memory before execution, and the CPU fetches instructions held in main memory.
Do this insteadTrace the program: storage, then main memory, then CPU.
Common mistake Thinking main memory is a permanent place to keep files
What it looks likeExpecting a document or program to still be in main memory after the computer is switched off.
Why it failsMain memory is volatile and keeps its information only while power is on.
Do this insteadUse storage devices for permanent information and main memory for what the CPU is working with.
Common mistake Thinking binary patterns are only numbers, separate from instructions
What it looks likeBelieving an instruction and a number are stored in different kinds of material.
Why it failsComputer instructions and data are both encoded as binary, represented by switches on for 1 and off for 0.
Do this insteadTreat instructions and data as binary patterns; meaning depends on how the CPU uses them.
Common mistake Assuming every device in the computer belongs to the CPU and main memory pair
Why it failsThe CPU and main memory form the central execution pair, but other devices such as hard disks and solid state drives sit outside it.
Checking the Route Yourself
A spreadsheet file is saved on a solid state drive, and a user opens it so the CPU can work with its data. Describe the route the data takes from the drive to the CPU, and explain why the file is still available the next day even though it is not kept in main memory.
Hints
- Start by asking where the file is kept permanently.
- Think about the step that must happen before the CPU works with the data.
- Consider what main memory keeps and for how long.
Key Takeaways
- Binary patterns of 1s and 0s encode both machine language instructions and data, with on corresponding to 1 and off to 0.
- The CPU and main memory form the central execution pair: the CPU fetches and executes instructions held in main memory.
- Storage devices such as hard disks and solid state drives keep larger amounts of information permanently, while main memory is volatile and comparatively small.
- A program must be loaded from storage into main memory before the CPU can execute it, so its path runs storage to main memory to CPU.
- An event is asynchronous in this context when it involves a device outside the CPU and main memory pair, such as a storage device.