Skip to main content
Be Bitwise

Instruction Set Basics

Registers & Instruction Sets · Foundations track

3 min read

In this module

The CPU's Vocabulary

An Instruction Set Architecture (ISA) defines every operation a CPU can perform. It's the contract between hardware and software. If a CPU implements a particular ISA, any program written for that ISA will run on it. Think of the ISA as the CPU's vocabulary: the complete list of words it understands.

Well-known ISAs include x86 (most desktops and laptops), ARM (most phones and tablets), and RISC-V (an open-standard ISA gaining traction in education and embedded systems).

RISC vs. CISC

ISAs generally fall into two design philosophies:

CISC (Complex Instruction Set Computing) hands you a large number of instructions, some of which do quite complex things in a single step. x86 is the classic CISC architecture. One instruction might load a value from memory, add it to a register, and store the result back.

RISC (Reduced Instruction Set Computing) favours a smaller set of simple, uniform instructions, designed so a pipelined CPU can finish about one per clock cycle. (Loads that miss the cache, multiplies and divides still take longer.) ARM and RISC-V follow this approach. Complex operations get built by stitching together simple instructions.

Neither philosophy is strictly better. CISC expresses complex operations compactly. RISC keeps the hardware simpler, which tends to lead to higher clock speeds and easier pipelining. Modern CPUs often blur the line. Today's x86 chips internally translate their CISC instructions into simpler micro-operations.

Here's the difference on one line of C, with a, b and x as local variables kept in memory. The listings are the sort of thing a compiler produces with optimisation turned off; exact offsets and registers vary by compiler. Click a line to see which instructions it became.

x86-64 (CISC): three instructions

x86-64
C Source
1// a, b and x are ints in memory
2x = a + b;
Assembly
1mov eax, DWORD PTR [rbp-8] ; load a
2add eax, DWORD PTR [rbp-12] ; add b, read straight from memory
3mov DWORD PTR [rbp-16], eax ; store x

Hover over code lines or mapping badges to see correspondences

RISC-V (RISC): four instructions

RISC-V
C Source
1// a, b and x are ints in memory
2x = a + b;
Assembly
1lw a4, -20(s0) # load a
2lw a5, -24(s0) # load b
3add a5, a4, a5 # add, registers only
4sw a5, -28(s0) # store x

Hover over code lines or mapping badges to see correspondences

The x86 add reads one of its operands directly from memory. RISC-V's add can't: only loads and stores touch memory, so b needs its own lw first. One extra instruction, but every instruction is simple and the same size, which is exactly the trade described above.

Key Concept

An ISA (Instruction Set Architecture) defines everything a CPU can do. RISC architectures use simpler, uniform instructions that each do less work; CISC architectures use more complex instructions that can accomplish more in a single step. The ISA is the interface between the software you write and the hardware that executes it.

Common Instruction Categories

Whatever the ISA, instructions tend to fall into a few groups:

  • Data movement. Load a value from memory into a register, store a register value to memory, copy between registers. Examples: LOAD, STORE, MOV.

  • Arithmetic and logic. Add, subtract, AND, OR, shift. These use the ALU. Examples: ADD, SUB, AND, SHL.

  • Control flow. Change which instruction executes next. Unconditional jumps (JMP), conditional branches (BEQ, branch if equal), and function calls (CALL, RET).

Every program, no matter how sophisticated, compiles down to some mix of these three categories. Get them in your head and you have a working mental model of what the CPU is doing when it runs your code.