Instruction Sets & Machine Code

Computers do not natively understand English words, Python scripts, or mathematical equations. At the electronic circuit level, a processor understands only machine code—sequences of binary digits ($0$s and $1$s) that activate specific logic gates within the CPU.


Learning Objectives

  • Define an instruction set and explain why machine code is hardware-dependent.
  • Describe the structure of a machine-code instruction: Opcode and Operand.
  • Differentiate between Immediate Addressing and Direct Addressing.
  • Explain the relationship between Assembly Language mnemonics and raw Machine Code.

What Is an Instruction Set?

An Instruction Set Architecture (ISA) is the complete collection of all machine-code instructions that a specific CPU design understands and can execute.

  • Hardware Hardwired: The instruction set is physically built into the silicon wiring and microcode of the Control Unit and ALU.
  • Hardware Dependent: Different processor families have different instruction sets:
  • x86 / x86-64 (Intel, AMD): Complex Instruction Set Computer (CISC) used in traditional desktops and servers.
  • ARM (Apple Silicon, Snapdragon): Reduced Instruction Set Computer (RISC) used in smartphones, tablets, and modern laptops.
  • Incompatibility: Because the binary opcodes are hardware-specific, machine code compiled for an Intel CPU cannot run directly on an ARM CPU; it must be recompiled from source code or run inside an emulator.

Optional extension: Anatomy of a Machine Instruction

In this simplified example, an instruction has an opcode and an explicit operand. Other instruction formats can differ:

$$\text{Instruction} = \text{Opcode} + \text{Operand}$$
+------------------------------------------+------------------------------------------+
|                 OPCODE                   |                 OPERAND                  |
|    Specifies the operation to perform    |    Specifies the data value or address   |
+------------------------------------------+------------------------------------------+

1. Opcode (Operation Code)

  • The unique binary code that identifies the specific operation the CPU must perform.
  • Examples of CPU operations:
  • Data transfer commands: LOAD, STORE
  • Arithmetic commands: ADD, SUBTRACT
  • Logical operations: AND, OR, COMPARE
  • Control flow commands: JUMP, BRANCH_IF_ZERO

2. Operand

  • Contains the parameters, data, or memory address needed to execute the opcode.
  • Depending on the instruction, the operand may contain:
  • A literal data value.
  • A primary memory (RAM) address.
  • A specific CPU register identifier (e.g. R1, R2, ACC).

Optional extension: Addressing Modes

The way the CPU interprets the operand bits is determined by the addressing mode:

1. Immediate Addressing

  • Definition: The operand field contains the actual data value to be used directly in the calculation.
  • Example in Assembly:
ADD #25

(Add the literal number $25$ directly to the Accumulator).

  • Advantages: Fast execution because no extra memory access to RAM is needed.
  • Limitations: The size of the data value is restricted by the bit-width of the operand field.

2. Direct Addressing

  • Definition: The operand field contains the memory address where the required data is stored in RAM.
  • Example in Assembly:
ADD 250

(Go to memory address $250$ in RAM, fetch the number stored there, and add it to the Accumulator).

  • Advantages: Can access dynamic data that changes during program execution.
  • Limitations: Requires an extra memory read cycle over the system bus to fetch the data from RAM.

Assembly Language vs Machine Code

Writing software directly in raw binary machine code (10110000 00000101) is extremely tedious and prone to error.

To simplify low-level programming, engineers created Assembly Language:

  • Replaces binary opcodes with short, human-readable text mnemonics:
  • LDA $\implies$ Load into Accumulator
  • STO $\implies$ Store Accumulator value into memory
  • ADD $\implies$ Add to Accumulator
  • SUB $\implies$ Subtract from Accumulator
  • JMP $\implies$ Jump to instruction address
  • One-to-One Translation: There is a direct 1:1 relationship between an assembly language mnemonic and a machine-code instruction.
  • The Assembler: A dedicated software translator called an assembler translates assembly language mnemonics directly into binary machine code.

Written practice and self-review

A software company writes a program in C++ and compiles it into an executable file on an Intel x86 desktop computer.

When a user attempts to run this compiled executable file directly on a smartphone powered by an ARM processor, the program fails to execute.

  1. Define what is meant by a processor's instruction set.
  2. Explain why the x86 machine-code executable cannot be executed directly by the ARM processor.

Write an explanation before checking the theory. Check that each claim answers the question, uses the correct concept and explains why it applies. Discuss uncertain points with a teacher. The structured exercise below checks specific facts; it does not automatically mark this explanation.

AI Socratic Tutor

All-Access
Sign in or create an account. AI Tutor is an All-Access benefit.
Sign Up

Need guidance? Ask a question or use the hint below.

AI Socratic Tutor is an All-Access Benefit

Unlock step-by-step Socratic hints, algorithm trace table walkthroughs, and error diagnostics for every Cambridge exercise.

You're chatting with an AI tutor, not a person. AI can make mistakes, so double-check its answers.

Exam-Style Question: Distinguishing Addressing Modes

+35 XP

Complete each statement regarding machine instructions and addressing modes:

  1. The portion of an instruction specifying the command or operation for the CPU to perform is the [Space 1].
  2. In [Space 2] addressing, the operand field contains the actual numerical data value to be used.
  3. In [Space 3] addressing, the operand field contains the memory address in RAM where the data value is stored.
Word Bank / Available Cards (Drag into spaces or tap to place)

All-Access Required

Interactive exercises for Module 2 and beyond require an active plan.