Understand the instruction set
Computer Architecture: The Instruction Set
What is an Instruction Set?
Think of a computer as a super‑fast kitchen 🏗️. The instruction set is the menu that tells the chef (the CPU) what dishes (operations) it can cook. Each line on the menu is an instruction that the CPU can understand and execute.
Types of Instructions
- Data movement:
LOAD,STORE– moving food between the fridge and the stove. - Arithmetic:
ADD,SUB– adding or subtracting ingredients. - Logical:
AND,OR– deciding which spices to use. - Control:
JMP,CALL– changing the recipe flow. - Input/Output:
IN,OUT– tasting and serving.
Instruction Format
Most instructions are written in binary, but we can think of them as a simple card with three parts:
| Field | Bits | Meaning |
|---|---|---|
| Opcode | 4‑bit | What the instruction does (e.g., 0010 = ADD). |
| Operand 1 | 4‑bit | First register or address. |
| Operand 2 | 4‑bit | Second register or address. |
Fetch‑Decode‑Execute Cycle
- Fetch: The CPU grabs the next instruction from memory. Imagine the chef reading the next line on the menu.
- Decode: The chef figures out what the instruction means. It’s like translating the recipe into actions.
- Execute: The chef performs the action—mixing, heating, tasting.
- Write‑Back: The result is stored back in memory or a register, ready for the next step.
Addressing Modes (How to Find the Food)
Addressing modes tell the CPU where the data is. Think of them as different ways to locate ingredients:
- Immediate: The value is right there in the instruction.
ADD #5means add the number 5. - Direct: The instruction gives the memory address.
LOAD 0x10fetches data from address 0x10. - Indirect: The instruction points to a register that holds the address.
LOAD [R1]means look at the address stored in register R1. - Register: The data is already in a register.
ADD R2, R3adds the contents of R2 and R3.
Example: Adding Two Numbers
Let’s add 7 and 3 using a simple 8‑bit machine.
| Step | Instruction | Result |
|---|---|---|
| 1 | LOAD R0, #7 | R0 = 7 |
| 2 | LOAD R1, #3 | R1 = 3 |
| 3 | ADD R0, R1 | R0 = 10 |
| 4 | STORE R0, 0x20 | Memory[0x20] = 10 |
Why It Matters
Understanding the instruction set is like learning the grammar of a language. Once you know the words (instructions) and how to combine them (addressing modes), you can write any program the computer can understand. It also helps you debug, optimise, and design better hardware.
Quick Quiz 🚀
- What does the
JMPinstruction do? - Give an example of an indirect addressing mode.
- Why is the fetch‑decode‑execute cycle important?
Revision
Log in to practice.