Concepts / Machine Code and Binary: What the CPU Actually Understands

Machine Code and Binary: What the CPU Actually Understands

The CPU is not best understood as performing one large task all at once. It repeatedly determines the next operation and carries it out through the fetch-decode-execute cycle.

  • Programming

The Question Behind Every Operation

The Central Processing Unit, or CPU, is the part of a computer built to keep asking one question: What is next? Its primary job is to determine the next operation to execute. A program can be understood as a list of instructions for the CPU to follow, while the CPU repeatedly retrieves, interprets, and carries out those instructions.

Key point

The CPU is not best understood as performing one large task all at once. It repeatedly determines the next operation and carries it out through the fetch-decode-execute cycle.

Following One Instruction

The CPU follows a repeating three-part process. First, it fetches the next instruction from memory. Next, it decodes the instruction, which means it figures out what the instruction means. Finally, it executes the operation. After execution, the CPU immediately returns to the fetch phase and looks for the next instruction.

FetchRetrieve instructionDecodeDetermine meaningExecutePerform operationNext instructioninstruction retrievedmeaning identifiedoperation completedrepeat
How does the CPU repeatedly move from an instruction in memory to an executed operation and then continue to the next instruction?
Worked example

Tracing the CPU's next decision

Describe what happens when the CPU is ready to process another instruction.

  1. 1
    Fetch

    The CPU retrieves the next instruction from memory.

  2. 2
    Decode

    The CPU figures out what the retrieved instruction means.

  3. 3
    Execute

    The CPU performs the operation described by the instruction.

  4. 4
    Continue

    The CPU immediately fetches the next instruction and repeats the cycle.

Result

The CPU does not stop after one instruction. It continuously cycles through fetch, decode, and execute.

What Machine Code Means Here

For this lesson, machine code can be treated as the instructions that the CPU fetches, decodes, and executes. The provided material focuses on the CPU's instruction cycle rather than specifying the binary encoding of individual instructions. The key point is that the CPU works directly through instructions and operations, repeating the cycle at very high speed.

InstructionFetched from memoryMeaningDetermined during decodeOperationPerformed by CPUdecodeexecute
How does an instruction move from something stored in memory to an operation the CPU can perform?

The Parts Working Together

The CPU's question is answered by several internal components working together. 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, very 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 dataCacheFrequently used dataALUCalculations and logicExecuted operationinstructioncoordinateprovide dataworking datadirect operationperform
How do the CPU's main internal components contribute to receiving, interpreting, and carrying out instructions?

Measuring CPU Frequency

CPU speed is measured in Gigahertz, abbreviated GHz. One Gigahertz means one billion cycles per second. Therefore, a 3.0 GHz CPU is described as asking What is next? three billion times per second. The source describes modern CPUs as often operating between 2.0 and 5.0 GHz, although some specialized processors can operate even faster.

0 seconds3.0 GHzThree billion cycles persecond1 secondCPU cycles repeatthree billion cycles
How does a CPU frequency of 3.0 GHz relate to repeated CPU cycles during one second?
Worked example

Interpreting a CPU rating

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

  1. 1
    Read the unit

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

  2. 2
    Apply the number

    The number 3.0 indicates three Gigahertz, or three billion cycles per second.

  3. 3
    Connect it to the CPU's role

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

Result

A 3.0 GHz CPU is associated with three billion cycles per second.

Why Repetition Matters to Programmers

The CPU can follow instructions at incredible speed, but repeated work still matters. If a program contains a loop that runs a million times and each iteration performs unnecessary work, the CPU repeats that unnecessary work a million times. Efficient code helps the CPU avoid needless operations, while inefficient code can multiply a small problem across many repetitions.

In the real world

Imagine a program with one unnecessary operation inside a loop that runs one million times. The CPU does not treat that operation as a one-time mistake; it encounters it during every iteration. The source uses this relationship between repetition and unnecessary work to explain why efficient code matters.

  • Common mistake

    Thinking of the CPU as completing a whole program in one indivisible action.

    What it looks like

    Describing a program as something the CPU simply finishes all at once.

    Why it fails

    The CPU follows a repeating fetch-decode-execute cycle and determines the next operation continuously.

    Do this instead

    Trace a program as a sequence of instructions that the CPU fetches, decodes, and executes.

  • Common mistake

    Treating GHz as a description of the program's entire behavior.

    What it looks like

    Assuming that a higher GHz label alone explains every aspect of how a program runs.

    Why it fails

    The source defines GHz as cycles per second and uses it to describe CPU operating frequency.

    Do this instead

    Use GHz to discuss cycles per second, then separately consider what instructions and repeated work the program requires.

  • Common mistake

    Ignoring repeated unnecessary work inside a loop.

    What it looks like

    Leaving an unnecessary operation in a loop that runs a million times.

    Why it fails

    The CPU repeats that unnecessary operation during every iteration.

    Do this instead

    Look for work that can be removed or avoided when it is repeated.

  • Common mistake

    Assuming this lesson provides exact binary encodings for machine instructions.

    Why it fails

    The source explains the CPU's instruction cycle but does not specify individual binary bit patterns.

    Do this instead

    Use this lesson to understand how instructions are fetched, decoded, and executed, without claiming a particular binary encoding.

Check Your Understanding

What do you think happens?

A CPU has fetched an instruction and figured out what it means. What phase comes next?

  • Fetch

  • Decode

  • Execute

  • Stop permanently

Reveal answer
Answer:

Execute

The fetch-decode-execute cycle places execution after the CPU decodes the instruction. After executing, the CPU returns to fetch the next instruction.

EASY

Explain the fetch-decode-execute cycle in three ordered steps. Then explain what 2.0 GHz means using the definition of Gigahertz.

Hints
  • Begin with the instruction's movement from memory.
  • Name the phase in which the CPU determines what the instruction means.
  • Remember that one Gigahertz means one billion cycles per second.

Key Takeaways

  1. 1
    The CPU is the part of the computer whose central role is determining what operation comes next.
  2. 2
    The CPU repeatedly fetches an instruction, decodes its meaning, executes the operation, and fetches the next instruction.
  3. 3
    The Control Unit, ALU, registers, and cache work together during instruction execution.
  4. 4
    One Gigahertz means one billion cycles per second; a 3.0 GHz CPU is described as carrying out three billion cycles per second.
  5. 5
    Because repeated work is repeated at CPU speed, unnecessary operations inside loops can become costly.

At a glance

  • The CPU repeatedly asks What is next? by determining the next operation to execute.
  • Its basic instruction process is fetch, decode, execute, followed by another fetch.
  • Gigahertz measures cycles per second, with one GHz equal to one billion cycles per second.
  • The Control Unit, ALU, registers, and cache cooperate to support instruction execution.
  • Efficient code matters because unnecessary work can be repeated many times at CPU speed.

More concepts starting with M