18 min read Intermediate Lesson 22 of 29
Part 4 — Instruction Set & Decoding

How CPUs Understand Machine Instructions: Opcode, Operand & ISA

When a CPU receives a stream of binary 0s and 1s from memory, how does it know whether to perform an addition (ADD), a memory read (LOAD), or a branch jump (JUMP)? Learn how instructions are encoded, decoded, and executed in silicon.

Machine Code: The Universal Language of Silicon

Every high-level algorithm, graphical video game, and neural network ultimately boils down to a sequence of binary opcodes and operand registers executed by digital logic gates.

1–5. Machine Instructions: What are Opcodes and Operands?

A machine instruction fundamentally splits into two key parts:

┌─────────────────────────────┬──────────────────────────────────────────┐
│ Opcode (Operation Code) │ Operands (Targets / Data) │
├─────────────────────────────┼──────────────────────────────────────────┤
│ What action to do? │ Who to act upon? │
│ (ADD, LOAD, JUMP) │ (Registers: R1, R2 / Address) │
└─────────────────────────────┴──────────────────────────────────────────┘

Example: ADD R1, R2, R3 instructs the CPU to add the contents of registers R2 and R3 and store the sum into register R1.

6–10. Instruction Decoder & Control Signals

Instruction Register (IR) & Decoder

Instructions fetched from memory are temporarily stored in the Instruction Register (IR). Combinational decoder circuits analyze the opcode bits to determine which functional units must activate.

Internal Control Signals

The decoder instantly energizes internal control lines: "Enable Register R1 output", "Enable Register R2 output", "Set ALU multiplexer to Addition mode", and "Latch result into Register R3".

11–17. Addressing Modes: Finding Data in Registers and Memory

1. Immediate Addressing

ADD R1, 5 — The constant numerical value (5) is encoded directly inside the instruction itself.

2. Register Addressing

ADD R1, R2 — The operation directly reads and writes values stored in ultrafast hardware registers.

3. Direct / Absolute Addressing

LOAD R1, [0x1000] — Loads data directly from a static, explicit memory address.

4. Base + Offset (Indexed)

LOAD R1, [RBX + 16] — Computes an effective memory address by adding an offset to a base pointer register.

18–24. ISA: RISC vs CISC and Processor Architectures

The ISA (Instruction Set Architecture) defines the official vocabulary and grammatical contract between software and hardware:

x86-64 (CISC) Variable Length (1–15 bytes)
ADD RAX, RBX
ARM64 (RISC) Fixed Length (4 bytes)
ADD X0, X1, X2
RISC-V (Open RISC) Modular Standard
ADD x5, x6, x7

Because each ISA defines different binary bit encodings, machine code compiled for x86 processors cannot execute natively on an ARM chip without dynamic binary translation or emulation.

35–38. Complete Instruction Pipeline Journey

Instruction Fetch (PC ──► I-Cache) │ ▼ Instruction Decode (Opcode + Operands Identifiers) │ ▼ Register Read & Rename (Fetch values into Reservation Stations) │ ▼ Execute (ALU / FPU / SIMD Operation) │ ▼ Memory Access (Load / Store Unit if RAM required) │ ▼ Write Back & In-Order Retire (Commit result to Architectural Registers)

45–48. Privileged Instructions & System Calls

Standard user-mode applications cannot execute all CPU instructions. Modifying page tables, toggling interrupt masks, or directly issuing raw disk commands require Privileged Instructions restricted to Kernel Mode (Ring 0). If user code attempts these operations, the CPU triggers a General Protection Fault exception.

51–55. Master Software-to-Hardware Translation Stack

HUMAN INTENT: z = x + y │ ▼ HIGH LEVEL CODE (Python / C++) │ ▼ COMPILER / RUNTIME (LLVM/GCC) │ ▼ MACHINE CODE BINARY (01001000 00000001) │ ▼ INSTRUCTION DECODER (IR) │ Decoded Opcode & Control Lines │ ▼ ALU & EXECUTION REGISTERS (RAX, RBX) │ ▼ LOGIC GATES (NAND, NOR, XOR) │ ▼ TRANSISTORS & VOLTAGE SWITCHING

🧠 Key Takeaways

  • Machine Instruction: Raw binary instructions executed directly by silicon processor hardware.
  • Opcode & Operand: The Opcode designates what action to take, while the Operands specify which registers or addresses to act upon.
  • Instruction Decoder: Translates binary bit patterns into electrical control signals directing internal CPU data paths.
  • Addressing Modes: Immediate, Register, Direct, and Base+Offset determine how effective operand locations are calculated.
  • ISA vs Microarchitecture: ISA is the permanent software contract; microarchitecture is the internal hardware design.
  • Stored-Program Concept: Both program instructions and data reside as identical binary patterns within unified memory.
🚀 Next Lesson

Lesson 23 — The Complete Lifecycle of a Program: From Double-Click to Result

Trace every single step from a mouse double-click interrupt to OS binary loading, process virtual memory paging, CPU scheduling, and screen rendering.