Stage 1 · Lesson 4 of 7
The fetch, decode, execute cycle
A runs a program by repeating one loop: , also called the instruction cycle. First it fetches the next instruction from memory. The address of that instruction sits in a special register called the program counter.
Then it decodes the instruction, working out what it means. Then it executes it, and moves on to the next one unless a jump says to go somewhere else. Instructions are very simple: load a value from memory into a register, add two registers, compare two values, jump.
Your if statements, loops and function calls all compile down to these few kinds of steps. Reading a little , the readable form of these instructions, from a compiler makes this concrete. This matters for the next topics.
How fast memory responds decides how fast this loop runs. The decides which program the loop is running.
Common trapthinking a single line of code is a single instruction.
A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CourseFreeCS50: Introduction to Computer Science
Harvard University · Beginner
The first weeks in C teach binary, memory, pointers and the stack and heap with excellent problem sets
- VideoFreeCrash Course Computer Science
CrashCourse · Beginner
Short videos from transistors to CPUs and memory; the quickest way to see the whole picture