Understand the instruction set

Resources | Subject Notes | Computer Science

IGCSE Computer Science - Instruction Set

Computer Architecture - Instruction Set

Introduction

The instruction set of a computer defines the set of instructions that the central processing unit (CPU) can understand and execute. These instructions are fundamental to how a computer performs tasks, from simple arithmetic to complex data manipulation. Understanding the instruction set is crucial for comprehending how computer programs work at a low level.

Instruction Set Architecture (ISA)

The ISA is the interface between the hardware and the software. It specifies the instructions a CPU can execute, the data types it can handle, and the addressing modes it supports.

Instruction Format

Instructions are typically represented in binary format. A typical instruction consists of an opcode (operation code) and one or more operands (data or memory addresses).

The format of an instruction can vary depending on the architecture. Common formats include:

  • Fixed-length instructions: All instructions occupy the same number of bits.
  • Variable-length instructions: Instructions can vary in length.

Instruction Types

Instructions can be broadly categorized based on their function:

  • Arithmetic Instructions: Perform mathematical operations (e.g., addition, subtraction, multiplication, division).
  • Logical Instructions: Perform logical operations (e.g., AND, OR, NOT, XOR).
  • Data Transfer Instructions: Move data between registers, memory, and input/output devices.
  • Control Flow Instructions: Alter the order of instruction execution (e.g., jumps, conditional jumps, calls, returns).
  • Stack Instructions: Operate on the stack data structure.

Instruction Set Examples (Simplified)

Here's a simplified table illustrating some common instruction types and their potential binary representations (note: actual representations vary by architecture).

Instruction Type Operation Example (Simplified Binary)
Addition Add two numbers in registers $0001\ 0010\ 0000$
Subtraction Subtract one number from another $0010\ 0010\ 0000$
Data Move Move data from memory to a register $1010\ 0001\ 0000$
Jump Unconditionally jump to a different instruction $0000\ 0000\ 1010$
Conditional Jump Jump to a different instruction based on a condition $1011\ 0000\ 1010$

Addressing Modes

Addressing modes specify how the operand in an instruction is located. Common addressing modes include:

  • Immediate Addressing: The operand is directly included in the instruction.
  • Register Addressing: The operand is located in a CPU register.
  • Direct Addressing: The operand's memory address is specified directly in the instruction.
  • Indirect Addressing: The instruction contains the address of a memory location that holds the actual operand's address.
  • Indexed Addressing: The operand's address is calculated by adding a register value to a base address.

Instruction Execution Cycle

The execution of an instruction typically involves the following steps:

  1. Fetch: The instruction is fetched from memory.
  2. Decode: The instruction is decoded to determine the operation to be performed.
  3. Execute: The operation specified by the instruction is executed.
  4. Write Back: The result of the operation is written back to a register or memory.

Registers

Registers are small, high-speed storage locations within the CPU. They are used to hold operands, addresses, and temporary results during instruction execution. Different types of registers serve specific purposes, such as:

  • Accumulator: Used for arithmetic and logical operations.
  • Program Counter (PC): Holds the address of the next instruction to be executed.
  • Instruction Register (IR): Holds the currently executed instruction.
  • Memory Address Register (MAR): Holds the address of a memory location to be accessed.
  • Memory Data Register (MDR): Holds the data being read from or written to memory.

Further Study

For a deeper understanding, explore different CPU architectures (e.g., RISC vs. CISC) and specific instruction sets like x86 or ARM.