Concepts / Memory and Storage: How Computers Remember

Memory and Storage: How Computers Remember

The CPU is the computer's decision-maker for instruction execution. It repeatedly determines the next operation to perform.

  • Programming

The Question Behind Every Operation

A computer appears to perform many different activities: it calculates, displays information, and runs programs. At the center of these activities is the Central Processing Unit, or CPU. The CPU is the part of the computer built to keep determining what should happen next. Its fundamental question is: What is next?

Key point

The CPU is the computer's decision-maker for instruction execution. It repeatedly determines the next operation to perform.

FetchRetrieve an instructionDecodeDetermine its meaningExecutePerform the operationNext instructionBegin againinstruction retrievedmeaning determinedoperation completedfetch again
What happens as the CPU determines one operation and proceeds to the next?

Following One Instruction

Worked example

Tracing a Single CPU Decision

Trace what the CPU does when it is ready to process the next instruction.

  1. 1
    Fetch

    The CPU retrieves the next instruction from memory.

  2. 2
    Decode

    The CPU determines what the retrieved instruction means.

  3. 3
    Execute

    The CPU performs the operation described by the instruction.

  4. 4
    Repeat

    The CPU immediately returns to the beginning and fetches the next instruction.

Result

The CPU does not process a program as one single, undifferentiated event. It repeatedly fetches, interprets, and performs instructions.

The fetch-decode-execute cycle is the basic pattern behind CPU instruction processing. Fetch means retrieving an instruction from memory. Decode means figuring out what that instruction means. Execute means performing the operation. After execution, the CPU fetches the next instruction and repeats the cycle.

How CPU Parts Work Together

The CPU does not answer its question alone. Several internal components contribute to instruction execution. The Control Unit directs the flow of instructions and coordinates the fetch-decode-execute cycle. The Arithmetic Logic Unit, or ALU, performs calculations and logical operations. Registers are tiny, ultra-fast storage locations that hold data the CPU is currently working with. The cache is a small, very fast memory that stores frequently used data so the CPU does not have to wait for slower main memory.

MemoryInstructions and dataControl UnitDirects instruction flowRegistersCurrent working dataALUCalculations and logicCacheFrequently used dataOperationInstruction executedinstructioncoordinatedirectavailable dataworking dataperform calculation or logiccoordinate
How do instructions and data move through the CPU's coordinating components?
CPU componentRole described in the source
Control UnitDirects instruction flow and coordinates the fetch-decode-execute cycle
Arithmetic Logic UnitPerforms calculations and logical operations
RegistersHold data the CPU is currently working with
CacheStores frequently used data in a small, very fast memory

The components that support the CPU's repeated instruction cycle

Reading a Gigahertz Rating

Definition

CPU speed is measured in Gigahertz, abbreviated GHz. One Gigahertz means one billion cycles per second.

Worked example

Interpreting 3.0 GHz

What does a 3.0 GHz CPU rating mean according to the source?

  1. 1
    Identify the unit

    GHz is Gigahertz, and one Gigahertz means one billion cycles per second.

  2. 2
    Apply the number

    A rating of 3.0 GHz corresponds to three billion cycles per second.

  3. 3
    Connect the rating to the CPU's question

    In the source's explanation, the CPU asks What is next? three billion times per second.

Result

A 3.0 GHz CPU is described as operating at three billion cycles per second.

Start0 secondsCPU cycleOne cycleCPU cycleRepeated cycleOne billion cycles1 GigahertzOne secondElapsed timecycle beginsrepeatcontinue repeatingwithin
What does one Gigahertz represent when the CPU repeats its cycle over one second?

The Scale of Modern CPU Activity

The numbers involved are difficult to imagine. The source describes modern CPUs as often running between 2.0 and 5.0 GHz, while some specialized processors can go even faster. At 3.0 GHz, the source presents the CPU as handling three billion decisions, three billion instruction fetches, and three billion execution cycles in one second.

One cycleOne decision sequenceRepeated cyclesThe cycle continuesBillions of cyclesWithin one secondNext operationCPU continuesrepeatscale upcontinue askingcycle again
How does a CPU's repeated cycle scale within a single second?
Key point

The CPU's speed matters because the same instruction pattern can be repeated an enormous number of times. A tiny amount of unnecessary work can become significant when repeated across many cycles.

Memory, Cache, and Working Data

The source describes memory as the place from which the CPU retrieves instructions. It also identifies registers and cache as important forms of fast working storage inside the CPU. Registers hold data currently being used, while cache keeps frequently used data close to the CPU so it does not have to wait for slower main memory.

MemoryInstructions retrievedRegistersCurrent working dataCacheFrequently used dataCPUInstruction executioninstructionworking datafrequently used data
How do the information-holding roles mentioned in the source differ during CPU work?

Why Repetition Changes Performance

When you write a program, you are giving the CPU a list of instructions to execute in order. The CPU can process those instructions at incredible speed, but that speed also magnifies repetition. If a loop runs a million times and each iteration performs unnecessary work, the CPU repeats that unnecessary work a million times. Efficient code reduces repeated work, helping the program feel instant to the user.

In the real world

Suppose a program performs the same unnecessary task during every iteration of a loop. The issue is not only the cost of one unnecessary task. The CPU repeats it for every iteration, so the total unnecessary work grows with the number of repetitions.

Key point

Understanding the CPU helps programmers judge code beyond whether it produces the correct result. Clear, efficient instructions make better use of the CPU's repeated cycles.

Mistakes Beginners Make

  • Common mistake

    Thinking the CPU has only one job: arithmetic

    What it looks like

    Describing the CPU as a calculator and leaving out instruction retrieval and interpretation

    Why it fails

    The source presents the CPU's primary role as determining the next operation. The ALU performs calculations and logical operations, but it is one component working inside the larger CPU process.

    Do this instead

    Describe the CPU as the part of the computer that repeatedly fetches, decodes, and executes instructions.

  • Common mistake

    Treating Gigahertz as a count of complete programs per second

    What it looks like

    Saying that a 3.0 GHz CPU runs three billion complete programs per second

    Why it fails

    The source defines Gigahertz as one billion cycles per second, not complete programs per second.

    Do this instead

    Say that a 3.0 GHz CPU is described as operating at three billion cycles per second.

  • Common mistake

    Stopping after execution

    What it looks like

    Describing fetch, decode, and execute as a process that happens once

    Why it fails

    After execution, the CPU immediately fetches the next instruction and repeats the cycle.

    Do this instead

    Include the repeating return from execution to the next fetch.

  • Common mistake

    Ignoring repeated unnecessary work in code

    What it looks like

    Assuming a small inefficiency does not matter because one extra operation is cheap

    Why it fails

    A loop can repeat the unnecessary work many times, and the source emphasizes that these repetitions can be multiplied across CPU cycles.

    Do this instead

    Look for work that is repeated unnecessarily, especially inside loops.

Check Your Understanding

EASY

Explain the path of one instruction from the moment the CPU retrieves it until the CPU begins working on the following instruction.

Hints
  • Name the three stages in order.
  • State what happens during each stage.
  • Remember what happens immediately after execution.
MEDIUM

A computer is rated at 5.0 GHz. Using the definition in this lesson, explain what the number 5.0 represents and identify what it does not directly tell you.

Hints
  • Start with the meaning of one Gigahertz.
  • Multiply that meaning by 5.0.
  • Do not describe the rating as complete programs per second.
MEDIUM

A loop repeats one million times and performs unnecessary work on every iteration. Why can that inefficiency matter even though the unnecessary work in one iteration seems small?

Hints
  • Focus on repetition.
  • Connect the loop to the CPU's repeated instruction cycles.
  • Use the idea that inefficiencies are multiplied across iterations.

Essential Takeaways

  1. 1
    The CPU is the part of the computer that repeatedly determines what operation should happen next.
  2. 2
    The CPU follows the fetch-decode-execute cycle: retrieve an instruction, interpret it, perform it, and repeat.
  3. 3
    One Gigahertz means one billion cycles per second; a 3.0 GHz CPU is described as operating at three billion cycles per second.
  4. 4
    The Control Unit, ALU, registers, and cache work together to support instruction execution.
  5. 5
    Repeated unnecessary work can matter because a CPU performs cycles billions of times per second and a program may repeat that work many times.

At a glance

  • The CPU's defining question is What is next?
  • Every instruction follows the repeating pattern of fetch, decode, and execute.
  • Gigahertz measures cycles per second, with one Gigahertz equal to one billion cycles per second.
  • CPU components such as the Control Unit, ALU, registers, and cache cooperate during instruction processing.
  • Efficient code matters because repeated work can be multiplied across millions of program iterations and billions of CPU cycles.

Related concepts

More concepts starting with M