How the CPU Executes Instructions
The CPU works with data in main memory. If data begins in secondary memory, it must be brought into main memory before the CPU can process it.
Speed Before Persistence
When you run a program, the CPU does not work directly with the program file on a hard drive. The program must first be copied into main memory, where the CPU can access it quickly. This creates a fundamental division of responsibility: main memory supports active work, while secondary memory preserves programs and files for the long term.
The CPU works with data in main memory. If data begins in secondary memory, it must be brought into main memory before the CPU can process it.
The Execution Path
Opening a Web Browser
Trace what happens when a user opens a browser, loads a webpage, and then closes the browser without saving the page.
- 1Program loading
The browser application is stored on secondary memory, such as a hard drive. When the browser is opened, the operating system copies the program from secondary memory into main memory.
- 2Program execution
The CPU executes the browser code from main memory rather than working directly with the file on the hard drive.
- 3Web request
After the user enters a web address and presses Enter, the browser sends a request over a network connection.
- 4Webpage arrival
The web server sends webpage data back through the network. The arriving data is placed into main memory.
- 5Processing and display
The CPU processes the webpage data in main memory, and the webpage is displayed on the screen.
- 6Closing without saving
If the browser is closed without saving the page, the webpage data in main memory is lost. The browser application remains on the hard drive and can be loaded again later.
The CPU uses main memory for active execution and processing, while secondary memory keeps the browser application available for future use.
Main memory is fast and nearly as quick as the CPU, but it is volatile. Volatile memory requires continuous power to retain its data. Secondary memory is much slower, but it is non-volatile: it retains data without power. The computer therefore uses main memory for immediate work and secondary memory for long-term storage.
Volatility at Shutdown
A power cut removes all data from main memory. Data already stored in secondary memory remains available because secondary memory retains data without power. This is why a program can disappear from its active working state while the installed application or previously saved file remains on a drive.
Common mistake Assuming that data in main memory is automatically permanent.
What it looks likeA document is open and has been edited, but it has not been saved.
Why it failsThe edited data may exist only in volatile main memory.
Do this insteadSave the data to secondary memory when it must remain available after shutdown.
Common mistake Assuming that the CPU executes a program directly from its hard drive.
What it looks likeThinking of the hard drive as the place where the CPU performs its active work.
Why it failsThe CPU works with program information in main memory.
Do this insteadUnderstand the path as secondary memory to main memory to CPU.
Common mistake Treating speed and persistence as the same property.
What it looks likeExpecting the fastest memory to retain all data without power.
Why it failsMain memory is fast but volatile, while secondary memory is slower but non-volatile.
Do this insteadChoose main memory for active processing and secondary memory for long-term retention.
Secondary Storage Choices
Secondary memory is used when information must remain available without power. Common examples include hard disk drives, solid-state drives, and flash memory. Flash memory is commonly found in USB sticks and portable music players. These technologies are appropriate for long-term storage because they can retain data indefinitely without power.
| Memory type | Speed relationship | Power requirement | Appropriate role |
|---|---|---|---|
| Main memory | Fast and nearly as quick as the CPU | Requires power to retain data | Active program execution and data processing |
| Hard disk drive | Much slower than main memory | Retains data without power | Long-term storage of programs and files |
| Solid-state drive | Much slower than main memory | Retains data without power | Long-term storage of programs and files |
| Flash memory | Much slower than main memory | Retains data without power | Portable long-term storage, including USB sticks |
The central trade-off is fast active work versus persistent long-term storage.
When a program needs to work with a large file, explicitly read the file from secondary memory into main memory first. When the program's results must remain after the program finishes, explicitly write those results to secondary memory.
Remote Data over Networks
A network connection can provide access to data stored somewhere else, so it can act as a slow and unreliable form of secondary memory. The data is not immediately available beside the CPU. It must travel between the local computer and a remote system, and the arriving data is then placed into main memory for processing.
| Access method | Where data is located | Relative speed | Main limitation |
|---|---|---|---|
| Local secondary memory | On the computer's drive or flash device | Much slower than main memory | Data must still be loaded into main memory before CPU processing |
| Network connection | On a remote system | Slow and unreliable | Remote access can delay or prevent timely access |
Both methods provide non-volatile storage access, but network access adds a remote connection between the computer and the data.
Apply the Memory Model
What do you think happens?
A webpage has arrived over a network connection. Where must the webpage data be placed before the CPU processes it?
Reveal answer
In main memory
The webpage data arrives over the network and is placed into main memory. The CPU then processes the data from main memory.
For each situation, identify whether the information belongs in main memory, local secondary memory, or remote access over a network. Then explain what happens to the information if power is cut off before it is saved.
Hints
- Ask whether the CPU is actively processing the information.
- Ask whether the information must remain available without power.
- For remote information, consider the additional network connection.
- 1Locate the information's current home: main memory, local secondary memory, or a remote system.
- 2If the CPU must process it, identify the transfer into main memory.
- 3If the information must survive shutdown, identify the transfer into secondary memory.
- 4If the information comes from a network, account for the connection's slowness and unreliability.
The Memory Hierarchy
- 1The CPU executes programs and processes data from main memory, not directly from files on a hard drive.
- 2Main memory is fast and nearly as quick as the CPU, but it is volatile and loses data when power is cut off.
- 3Secondary memory is slower but non-volatile, so hard disk drives, solid-state drives, and flash memory can preserve programs and files without power.
- 4Saving explicitly copies data from main memory to secondary memory so it can persist after shutdown.
- 5Network connections provide remote data access but are slow and unreliable, making them unsuitable for critical, time-sensitive operations.
Key Takeaways
- The CPU needs program instructions and data in fast main memory to execute and process them.
- Main memory is volatile, while secondary memory is slower but retains data without power.
- Saving is the explicit movement of data from main memory to secondary memory.
- Hard disk drives, solid-state drives, and flash memory are examples of persistent secondary memory.
- Network connections can provide remote storage access, but their slowness and unreliability limit their use for time-sensitive work.