Base CS from zero
The instruction
You write a line of code and the computer does something — adds two numbers, stores a value, jumps to a different part of the program. But a CPU does not understand Python or JavaScript or C. It understands only one thing: a tiny, fixed vocabulary of ultra-simple commands called instructions. Every piece of software — from a browser to a game engine to an operating system — is ultimately reduced to a sequence of these tiny commands before the CPU can run it.
What exactly is one instruction? What does it look like, and what can it do?
After this lesson you can define what a CPU instruction is, explain the difference between an operation and an operand, give examples of the major instruction kinds (arithmetic, memory, and control-flow), and describe what an instruction set is.
An instruction is one indivisible command. A CPU instruction is the smallest unit of work the CPU can carry out as a single, atomic step. The CPU reads the instruction, does exactly what it says, and moves on to the next one. It does not break the instruction into smaller pieces — the instruction is already the smallest piece.
Think of a recipe card written for an extremely literal robot. Each card says exactly one thing: “Add the flour to the bowl,” “Set the oven to 180 °C,” “If the batter is lumpy, go back to step 3.” The robot cannot improvise. It carries out each card precisely as written and then looks at the next card. CPU instructions work the same way, except each card takes nanoseconds instead of seconds.
An instruction = an operation + its operands. Every instruction has two parts:
-
The operation (also called the opcode, short for operation code) says what to do. Examples: ADD, SUBTRACT, LOAD (read from memory), STORE (write to memory), JUMP (go to a different instruction).
-
The operands say what to do it to. They are the inputs the operation needs. ADD needs two numbers. LOAD needs an address to read from. JUMP needs the address of the next instruction to run.
An instruction with no operands is rare but possible (for example, a HALT instruction that stops the CPU needs no input).
Written informally, instructions look like this:
ADD R0, R1 ; add the value in slot R0 to the value in slot R1
LOAD R0, 100 ; read the byte at memory address 100 into slot R0
STORE 200, R1 ; write the value in slot R1 to memory address 200
JUMP 50 ; next, execute the instruction at address 50Here R0 and R1 are registers — small, ultra-fast storage slots inside the CPU
(you will learn about them in detail in the next lessons). For now, treat them as named
boxes that hold a value.
The three families of instructions. Real instruction sets have many instructions, but almost all of them belong to one of three families:
1. Arithmetic and logic instructions. These compute a result from one or two values. Common examples: ADD, SUBTRACT, MULTIPLY, AND, OR, NOT, SHIFT (move bits left or right). The inputs and output are held in registers. The CPU has a small circuit called the Arithmetic Logic Unit (ALU) that carries out these computations.
2. Memory instructions. These move data between registers and memory. A LOAD instruction reads a value from a memory address into a register. A STORE instruction writes a register’s value out to a memory address. These are the only way to get data from the giant but slow memory into the fast CPU, and back again.
3. Control-flow instructions. These change which instruction runs next. Normally, after
finishing one instruction, the CPU moves to the very next one (sequential execution). A
JUMP instruction overrides this: it sets the next instruction to be the one at a
specified address. A conditional JUMP (also called a branch) only jumps if some
condition holds (e.g., “jump to address 80 if the last result was zero”). Branches are how
if statements and loops are implemented in hardware.
Why this works
Why such a small, fixed vocabulary? The instruction set is implemented directly in hardware — silicon circuits that decode each operation code and route signals to the right parts of the chip. Building circuits for a huge, flexible vocabulary would make the chip enormous, slow, and power-hungry. Instead, CPU designers choose a small set of simple, composable operations. Complex behaviour (sorting a list, rendering a pixel) is built by combining many thousands of simple instructions. The compiler or interpreter is the program that does this translation.
The instruction set: the CPU’s complete vocabulary. The complete collection of instructions a specific CPU model understands is called its instruction set (more formally, its Instruction Set Architecture, or ISA). Different CPU families have different instruction sets:
- x86-64 is the instruction set used by Intel and AMD chips in most laptops and desktops.
- ARM (AArch64) is the instruction set used by the chips in iPhones, Android phones, and Apple Silicon Macs.
- RISC-V is a newer, open instruction set used in embedded systems and research.
A program compiled for x86-64 cannot run directly on an ARM chip, because the two chips do not share an instruction set. The instruction set is the contract between software and hardware.
Each instruction set has its own encoding — a specific pattern of bits that represents each instruction in memory. You will see this in detail in the lesson on machine code.
Common mistake
A common misconception is that the CPU “understands” programming languages. It does not. The CPU understands only the bit patterns of its instruction set. Python, JavaScript, C, and every other language must be translated — compiled or interpreted — into the CPU’s instruction set before the CPU can execute it. No matter how high-level the code you write, by the time it runs on the chip it has been reduced to a sequence of simple ADD, LOAD, STORE, JUMP, and similar instructions.
Identifying the parts of an instruction.
Consider this instruction:
ADD R2, R0, R1- Operation:
ADD— the opcode telling the CPU to perform addition. - Operands:
R2,R0,R1— three registers. This instruction means “add the value in R0 to the value in R1, and store the result in R2.”
Now consider:
STORE 500, R2- Operation:
STORE— write a value from a register to memory. - Operands: address
500and registerR2. This means “write whatever is in R2 into the memory cell at address 500.”
And finally:
JUMP 80- Operation:
JUMP— redirect execution. - Operand: address
80. This means “make the next instruction to execute be the one stored at memory address 80.” Without this instruction, the CPU would have gone to the next instruction in sequence.
In all three cases the structure is the same: one operation code, followed by the inputs that operation needs.
An instruction has two main parts: the operation and the ___. How many main parts does an instruction have? Type the number.
Which instruction family is responsible for reading a value from a memory address into the CPU? Type 1 for arithmetic, 2 for memory, 3 for control-flow.
A JUMP instruction changes the address of the next instruction to execute. Without a JUMP, the CPU runs instructions in what order? Type 1 for sequential (one after the next), 2 for random.
The complete set of instructions a CPU model understands is called its instruction ___. How many letters are in the missing word? (Hint: it is the word 'set'.) Type the number.
A compiled program for x86-64 can run directly on an ARM chip without any translation. Type 1 for true, 0 for false.
What is the difference between the operation and the operands of an instruction?
A CPU instruction is the smallest indivisible command the CPU can execute. Every instruction consists of an operation (opcode) that names the action, and zero or more operands that supply the inputs. Instructions fall into three main families: arithmetic and logic instructions that compute values, memory instructions (LOAD and STORE) that move data between registers and memory, and control-flow instructions (JUMP and branch) that change which instruction runs next. The complete set of instructions a CPU model understands is its instruction set (or Instruction Set Architecture, ISA). Different CPU families have different instruction sets, and software must be translated into the correct instruction set before the CPU can run it.