Skip to content
BetterDL

Instruction

Also called: machine instruction, CPU instruction

A single binary command a CPU can carry out, such as load, add, store or jump, stored as a word in memory.

An instruction is one step of a program as the hardware sees it: a binary word that tells the CPU to do one simple thing. Typical jobs:

  • move data between memory and registers (LOAD, STORE);
  • do arithmetic or logic (ADD, SUB);
  • change which instruction runs next (JMP, JZ);
  • stop (HALT).

Each instruction is split into fields by the instruction format. The opcode says what to do; other fields say which data or address to use. In Tiny8, 3E is ADD E: opcode 3 (ADD), address E.

In a stored program computer, instructions live in memory alongside data. A word becomes an instruction only when the program counter reaches it and the CPU fetches it. Then the CPU runs the fetch decode execute cycle on it.

The full list of instructions a CPU understands is its instruction set.

Worked examples

Example

What one instruction does

Tiny8 fetches 39 from address 2. M[9] = 6 and ACC = 4.

  1. 1.

    Opcode 3 = ADD. Address 9.

  2. 2.

    Meaning: ACC ← ACC + M[9].

  3. 3.

    Result: ACC = 4 + 6 = 10, Z = 0, and the PC is 3, pointing at the next instruction.

Example

Data that runs by accident

A Tiny8 program forgets its HALT, and the PC reaches a word the programmer meant as the number 64 (40).

  1. 1.

    40 decodes as opcode 4, address 0: SUB 0.

  2. 2.

    The CPU executes it, subtracting M[0] from the ACC.

  3. 3.

    The CPU can't tell intent. Any word the PC reaches is an instruction.

Common mistakes

  • Confusing an instruction with a line of high-level code. One line of code usually becomes several instructions.

  • Thinking words are marked as instructions in memory. Only the PC decides.

Practice Instruction

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Instruction is taught in Basic CPU / Computer Architecture.