Learning Objectives

By the end of this chapter, you will be able to:

  • Describe how a computer uses memory to run a program.
  • Explain the three steps of the CPU’s fetch-decode-execute cycle.
  • Understand the flow of data from secondary storage to RAM to the CPU.

How Computers Use Memory to Run Programs

For a computer to run a program (like a web browser or a word processor), the program’s instructions and data must be loaded from the slow secondary storage (like an SSD or HDD) into the much faster primary memory (RAM). The CPU can then access the instructions and data from RAM to execute the program.

This process is managed by the operating system and happens in a continuous loop known as the fetch-decode-execute cycle.

The Fetch-Decode-Execute Cycle

The CPU continuously performs three basic steps:

  1. Fetch: The CPU fetches the next instruction from its location in RAM.

  2. Decode: The CPU’s control unit decodes the instruction to understand what operation needs to be performed (e.g., add two numbers, move data).

  3. Execute: The CPU’s Arithmetic Logic Unit (ALU) executes the instruction. This might involve performing a calculation or moving data between registers, cache, and RAM.

This cycle repeats millions or billions of times per second, which is what allows the computer to perform complex tasks.

The Flow of Data

  1. When you launch an application, the operating system finds the program files on your secondary storage (e.g., your SSD).

  2. A copy of the program’s instructions and any necessary data is loaded into RAM.

  3. The CPU begins the fetch-decode-execute cycle, pulling instructions and data from RAM into its cache and then into its registers for immediate processing.

  4. As you work, any new data you create or changes you make are held in RAM. When you save your work, that data is written back to secondary storage for long-term preservation.

Summary

Computers use a hierarchical memory system to run programs efficiently. Programs are stored long-term on slower secondary storage and are loaded into faster RAM to be run. The CPU then pulls instructions and data from RAM, executing them in a continuous fetch-decode-execute cycle. This coordinated flow of data between storage, RAM, and the CPU is what allows a computer to function.

Key Takeaways

  • Programs must be loaded from secondary storage into RAM to be executed.
  • The CPU continuously performs the fetch-decode-execute cycle.
  • Data flows from storage to RAM to cache and registers for processing.

Discussion Questions

  1. What happens if you try to run too many programs at once and you run out of RAM?
  2. Why is the fetch-decode-execute cycle called a “cycle”?
  3. When you are typing a document, where are the words being stored before you hit “Save”?