Understand what machine code is and why it is the only language directly executed by the CPU
Describe the structure of an assembly language instruction (opcode + operand)
Interpret and write simple assembly programs using the OCR reference language
Explain the role of the assembler
Machine Code
Machine Code
Machine code is the lowest-level programming language, consisting entirely of binary digits (0s and 1s). It is the only language the CPU can execute directly — all other languages must be translated into machine code first.
Each instruction is a fixed-length binary pattern specific to the CPU's instruction set architecture (ISA). Instructions are processor-specific: code for an Intel x86 CPU will not run on an ARM processor.
Machine code is very difficult for humans to read and write directly. Errors are hard to spot, and code is completely non-portable across different processor architectures.
01001000 11000011 00000001 ← example machine code instructions
Assembly Language
Assembly Language Structure
Assembly language is a low-level language that uses mnemonics (short human-readable codes) as a one-to-one mapping to machine code instructions. Each assembly instruction translates to exactly one machine code instruction.
Instruction Format
OPCODEOPERAND
LDRR1, #5 ADDR1, R1, R2 STRR1, 200
Key Terms
Opcode: the operation to perform (e.g. LDR, ADD, STR, MOV, CMP, B)
Operand: the data or address to operate on (register, literal, memory address)
CMP R1, #5 ; set flags B LOOP ; unconditional BEQ LOOP ; if equal BNE LOOP ; if not equal BGT LOOP ; if greater BLT LOOP ; if less
Shifts
LSL R1, R1, #2 ; left shift LSR R1, R1, #1 ; right shift
Left shift = × 2 Right shift = ÷ 2 per bit shifted
The Assembler
Role of the Assembler
An assembler is a program that translates assembly language source code into machine code. It produces a one-to-one translation — each mnemonic maps to exactly one machine code instruction.
Two-pass assembler (common): first pass scans code to build a symbol table of all labels and addresses; second pass translates instructions replacing labels with their resolved addresses.
Symbol table: a table maintained by the assembler that maps label names (e.g. LOOP) to their memory addresses, enabling forward references to be resolved.
Unlike a compiler, an assembler does not optimise the code — the output is a near-direct binary equivalent of the assembly source.
Exam Practice
OCR H446 Style · 4 marks
Trace through the following assembly program and state the value in R3 at the end. LDR R1, #8 LDR R2, #3 SUB R3, R1, R2 LSL R3, R3, #1
[4 marks]
1
LDR R1, #8 → R1 = 8
1
LDR R2, #3 → R2 = 3
1
SUB R3, R1, R2 → R3 = 8 − 3 = 5
1
LSL R3, R3, #1 → R3 = 5 × 2 = 10 (left shift by 1 = multiply by 2)
Common Mistakes
Don’t Lose Marks
!
Saying assembly and machine code are the same — assembly uses human-readable mnemonics; machine code is binary. The assembler translates assembly into machine code. They are not the same thing.
!
Getting the operand format wrong — # means an immediate (literal) value e.g. #5; without # it refers to a memory address. These are fundamentally different and examiners will penalise confusion.
!
LSL and LSR direction confusion — LSL (Left Shift Logical) moves bits left, equivalent to multiplying by 2 per bit. LSR moves bits right, equivalent to dividing by 2 per bit.