How the CPU Executes Instructions
Main memory is fast and nearly as quick as the CPU, but it is volatile and loses all data when power is cut off.
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.
Program 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.
Program execution: The CPU executes the browser code from main memory rather than working directly with the file on the hard drive.
Web request: After the user enters a web address and presses Enter, the browser sends a request over a network connection.
Webpage arrival: The web server sends webpage data back through the network. The arriving data is placed into main memory.
Processing and display: The CPU processes the webpage data in main memory, and the webpage is displayed on the screen.
Closing 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.
Assuming that data in main memory is automatically permanent.
The edited data may exist only in volatile main memory.
Fix:
Save the data to secondary memory when it must remain available after shutdown.Assuming that the CPU executes a program directly from its hard drive.
The CPU works with program information in main memory.
Fix:
Understand the path as secondary memory to main memory to CPU.Treating speed and persistence as the same property.
Main memory is fast but volatile, while secondary memory is slower but non-volatile.
Fix:
Choose 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 |
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
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.
- Locate the information's current home: main memory, local secondary memory, or a remote system.
- If the CPU must process it, identify the transfer into main memory.
- If the information must survive shutdown, identify the transfer into secondary memory.
- If the information comes from a network, account for the connection's slowness and unreliability.
The Memory Hierarchy
- The CPU executes programs and processes data from main memory, not directly from files on a hard drive.
- Main memory is fast and nearly as quick as the CPU, but it is volatile and loses data when power is cut off.
- Secondary memory is slower but non-volatile, so hard disk drives, solid-state drives, and flash memory can preserve programs and files without power.
- Saving explicitly copies data from main memory to secondary memory so it can persist after shutdown.
- Network 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.