Technology & Computing · Computers & hardware
How processors execute instructions
Follow a tiny calculation through the instructions, memory addresses and circuits that make a computer work.

What you will learn
- Distinguish fetching, decoding and executing an instruction.
- Explain why a processor needs an encoded instruction as well as data.
- Explain what a processor must keep track of for a sequence of instructions to run at all.
- Distinguish the address of a memory location from the value stored there.
- Explain why a program must interpret the bytes it reads.
- Predict what happens when a program reads bytes under the wrong interpretation.
Lesson 1 of 4 · 6 min
What a processor does with 7 + 5
You type 7 + 5 into a calculator and 12 appears. It looks like one act. Inside, the processor did several smaller things in a fixed order, and it does those same few things for every task it's given.
A central processing unit, or CPU, is circuitry that carries out encoded instructions one after another. The processor described here is deliberately simple. Real chips overlap and reorder their work, but they have to produce the same results as the simple version.
Each instruction goes through three stages. Fetch gets the next instruction from memory. Decode works out which operation the instruction asks for and where its inputs are. Execute performs that operation, such as adding two values.
Then the cycle starts again with the next instruction. These are stages of one instruction cycle. They aren't three separate parts of the computer taking turns.
Take the sum. Say one instruction means "add these two values." Fetch brings that instruction in from memory. Decode recognizes it as an addition. Execute produces 12. A further instruction then stores the result where later work can find it.
Two parts of the chip share the work. The arithmetic and logic unit does the calculations and comparisons, and control circuitry coordinates the rest. Neither knows why you wanted the answer.
Inside the machine, an instruction and a piece of data look alike. Both are stored as bits, the ones and zeros a computer keeps. Which role a pattern plays depends on how the system uses it.
So the number 7 sitting in memory doesn't ask for anything. The processor also needs an operation and a way to find the values involved. Data supplies the ingredients, and an instruction says what to do with them.
Try to recallA memory location holds the value 12. Why isn't that enough to tell the CPU what to do?
The value is data. The CPU also needs an instruction that specifies an operation, such as add or compare, and says how to find its inputs or where the result goes.
Look again at the first stage. Fetch gets the next instruction, and the word "next" hides a requirement. The processor has to know where that instruction is.
It keeps the address in a small store called the instruction pointer. After each fetch, the pointer moves on to the following instruction. Without it, the machine would fetch the same instruction forever.
That one stored address is where a program's shape comes from. Normally the pointer steps forward, so instructions run in the order they're stored. But an instruction can also write a new address into the pointer.
Set the pointer back to an earlier address, and a section of the program repeats. Set it to one of two addresses, depending on a comparison, and the program takes one of two paths. The cycle never changes. It's still fetch, decode, execute.
Say a tiny program sits at three addresses. At address 10, subtract 1 from a counter. At address 11, if the counter isn't zero, set the pointer back to 10. At address 12, stop.
Start the counter at 3. The processor runs address 10 three times, though that instruction is stored only once. Each time, the instruction at 11 sends the pointer back. When the counter reaches zero, the pointer moves on to 12.
Real chips work on several instructions at once, so read "next" as the order of effects. It doesn't describe what each circuit is doing at a given instant.
Lessons in this topic
What a processor does with 7 + 5
Follow one small sum through fetch, decode and execute, then see how a single stored address lets a program repeat itself or choose a path.
Why a memory address isn't the value stored there
Tell a value from the address where it's kept, then see why the same stored numbers can be read as text, as a color or as nonsense.
Four small steps behind one running total
Follow a running total through read, add and store, see where the recipe comparison fails and learn to read a wrong result as a clue to the step that went wrong.
From typed text to machine code
Follow a program from human-readable source through the compiler's four stages to the bit patterns a processor executes.
Three quick stories from this topic
HI! is different from HI!
In C, typing HI! twice and comparing the two with == reports that they're different
The == test compares where each piece of text is stored, and the two copies sit at different addresses. Harvard's CS50 course uses the example to show that a memory address and the value kept there are separate things.
Think of numbered lockers
The number on the door identifies the locker, and the object inside is its contents. Two lockers can hold identical objects and still be different lockers.
Comparing the contents
To compare the letters themselves, a C programmer calls a function named strcmp, which looks at the characters stored at each address.
HI! or a shade of yellow
The three numbers that spell HI! in a text message are also a shade of yellow
A computer stores the characters H, I and ! as the numbers 72, 73 and 33. Hand the same three numbers to image software and it reads them as amounts of red, green and blue. Stored numbers don't say what they mean. The program reading them decides.
Bytes carry no label
A place in memory holds numbers and nothing else. Nothing stored there says whether they're text, part of a picture or an instruction.
Why software needs shared rules
Programs agree on standard codes, such as the one that maps 72 to the letter H. Read with the wrong rules, perfectly good bytes turn into nonsense.
One address set back
A processor repeats part of a program by setting one stored address back
The processor keeps the address of its next instruction in an instruction pointer, which normally steps forward. An instruction can write a new address there. Send the pointer back and a section runs again, so a loop is stored only once however many times it runs.
Fetch needs an address
In the simplified cycle, fetching gets the next instruction from memory, and the pointer supplies its location. Once the current instruction has been carried out, the next one moves into the instruction register, and the pointer indicates the one after that.
An address doesn't say what the instruction does
Knowing where the next instruction is says nothing about what it does. It still has to be decoded and executed. In IBM's simplified model of the cycle, a clock keeps time, and its pulses coordinate the circuitry at a rate called the clock speed, measured in hertz.
Sources
- What is a Central Processing Unit (CPU)? | IBM, IBM
- Lecture 4 - CS50x 2025, Harvard University CS50
- Program counter, Wikimedia Foundation
- Lecture 0 - CS50x 2025, Harvard University CS50





