Skip to topic
    ← Back to course topics

    Machine-code/assembly language operations — AQA A-Level Computer Science

    Machine code consists of binary instructions executed directly by the CPU, whereas assembly language uses human-readable mnemonics representing low-level opcodes and operands. Mastering assembly operations, addressing modes, and bitwise manipulation is critical for tracing processor registers and writing efficient algorithms for AQA A-Level Computer Science.

    Machine-code/assembly language operations explained

    This statement introduces the basic machine-code operations that you must understand and apply, and the specific operations are listed after the colon.

    Read the full explanation

    Machine-code operations are the low-level instructions a processor executes, typically moving data between registers and memory, performing arithmetic and logic, and controlling the flow of execution through jumps and branches. Assembly language provides a readable mnemonic for each machine-code instruction. To apply these operations, you should be able to read an instruction, identify its operation and operands, and predict its effect on registers and memory. For example, an instruction that adds the contents of two registers changes the destination register's contents, while a jump instruction changes the address of the next instruction to be fetched.

    Your focus

    1. Understand and apply the basic machine-code operations of:

    Which command word is this?

    Follow the step-by-step execution of code precisely, recording every register change chronologically in a trace table until execution halts.

    Machine-code/assembly language operations exam tips

    Topic Overview

    Machine code represents the fundamental native instructions executed directly by the central processing unit, consisting entirely of binary bit patterns divided into an opcode and one or more operands. Assembly language provides a human-readable mnemonic representation of this machine code, forming a direct one-to-one correspondence that allows low-level access to processor registers and system memory.

    Understanding assembly operations is central to AQA A-Level Computer Science because it bridges high-level procedural abstraction with physical computer architecture. It underpins how compilers generate executable code, how addressing modes determine operand retrieval, and how bit manipulation and status registers control hardware devices.

    Key Concepts
    • →Instruction Structure: Every machine instruction consists of an Operation Code (Opcode), which tells the control unit what operation to execute, and an Operand, which holds data or memory references.
    • →Addressing Modes: Immediate addressing ('#value') uses the operand directly as the datum, direct addressing uses the operand as the memory address of the datum, while register addressing uses processor registers.
    • →Status Register and Branching: The Compare instruction ('CMP') performs subtraction to update status flags (Zero, Negative, Carry), which conditional branch instructions ('BEQ', 'BNE', 'BGT', 'BLT') evaluate to direct program flow.
    • →Bitwise Logical Operations: 'AND', 'ORR', 'EOR', and 'MVN' operate on corresponding individual bits in registers, enabling masking techniques to isolate, set, or invert specific bits.
    • →Shift Operations: Logical Shift Left ('LSL') multiplies unsigned integers by powers of two by shifting bits left and inserting zeros, while Logical Shift Right ('LSR') divides by powers of two.
    Marking Points
    • Identifies the operation type of an instruction from its mnemonic or opcode.
    • Identifies the operands and the storage locations they refer to.
    • Predicts the effect of an instruction on registers or memory.
    • Traces the sequence of execution through a short program correctly.
    Examiner Tips
    • 💡Write down the effect of each instruction on registers or memory as you trace the program.
    • 💡Check the destination operand to see which storage location is changed.
    • 💡Trace execution in order, noting any jump that changes the next instruction.
    • 💡Always draw a trace table containing a column for each register and the Status Register condition flags whenever solving loop-based assembly questions.
    • 💡When asked to explain the difference between addressing modes, always provide an annotated example showing how the operand field is decoded by the CPU for each mode.
    • 💡Ensure you use valid AQA-specific mnemonics from the specification (e.g. 'LDR', 'STR', 'ADD', 'SUB', 'MOV', 'CMP', 'B', 'AND', 'ORR', 'EOR', 'LSL', 'LSR') rather than generic x86 or standard ARM syntax.
    Common Mistakes
    • Confuses the operation with its operands; the mnemonic states what is done, the operands state what it is done to.
    • Assumes an instruction changes memory when it only changes a register; check the destination carefully.
    • Ignores the effect of a jump or branch on the order of execution.
    • Believing assembly instructions can access two arbitrary main memory locations simultaneously; in load-store architectures, memory values must first be loaded into registers ('LDR') before arithmetic processing, and then stored back ('STR').
    • Confusing Logical Shift Right ('LSR') with Arithmetic Shift Right ('ASR'); LSR always inserts a zero into the most significant bit, whereas ASR preserves the sign bit to maintain correct two's complement negative values.
    • Assuming that conditional branch instructions execute the comparison themselves; a conditional branch like 'BNE' only reads the condition flags already stored in the Status Register by a preceding instruction like 'CMP' or 'SUB'.
    Revision Plan
    1. 1Day 1-3: Memorise the standard AQA instruction set mnemonics, distinguishing arithmetic, logical, data transfer, and branch instructions.
    2. 2Day 4-6: Practice manual register tracing using past exam trace tables, paying special attention to loop counter decrements and conditional flags.
    3. 3Day 7-9: Master bit masking and shifting exercises; write code snippets to extract, set, and toggle individual bits using AND, ORR, and EOR.
    4. 4Day 10-12: Write full assembly programs from high-level pseudocode algorithms, incorporating selection constructs ('IF-THEN-ELSE') and iteration ('WHILE', 'FOR').
    5. 5Day 13-14: Complete timed past paper questions assessing addressing modes, assembly theory, and machine-code binary instruction layouts.
    Exam Question Types
    • 📋Register Trace Tables: Candidates must track values across registers (R0, R1, R2, etc.) through sequential and branching instructions until a HALT instruction is reached.
    • 📋Code Conversion / Writing: Candidates must write short snippets of assembly code from a given specification or convert a high-level pseudocode loop into assembly.
    • 📋Bitwise Masking Problems: Candidates must supply the correct mask and bitwise operator (AND/ORR/EOR) to isolate or alter specific bit flags.
    • 📋Conceptual Questions on Addressing Modes: Candidates are asked to compare immediate, direct, indirect, and indexed addressing modes using diagrams or written definitions.
    Command Word Expectations (AQA)
    Trace

    Follow the step-by-step execution of code precisely, recording every register change chronologically in a trace table until execution halts.

    Explain

    Provide a detailed account of how a process works (e.g. how an addressing mode resolves an operand) with clear cause-and-effect reasoning.

    Write

    Construct syntactically accurate assembly code using the approved AQA instruction set to achieve the precise algorithmic outcome specified.

    How Students Lose Marks (Examiner Pitfalls)
    Pitfall: Confusing immediate addressing with direct addressing due to omitting the '#' symbol.
    ❌ Weak Answer (Loses Marks):The instruction 'MOV R1, 10' loads the number 10 into register R1.
    Example improved answer:In AQA assembly language, 'MOV R1, #10' uses immediate addressing to load the literal numeric value 10 into register R1. Omitting the hash symbol ('MOV R1, 10') indicates direct addressing, meaning the CPU loads the data stored at memory address 10 into R1.
    Examiner Tip: Always check for the '#' prefix in AQA assembly. A hash indicates an immediate constant operand, whereas its absence indicates a memory location reference.
    Pitfall: Assuming the 'CMP' instruction updates or overwrites a general-purpose register.
    ❌ Weak Answer (Loses Marks):CMP R1, R2 subtracts R2 from R1 and stores the result back in R1 before branching.
    Example improved answer:The CMP R1, R2 instruction performs an arithmetic subtraction (R1 - R2) without storing the result in any general-purpose register. Instead, it updates the conditional flags (Zero, Negative, Carry, Overflow) in the Status Register, which conditional branching instructions like BEQ and BLT evaluate.
    Examiner Tip: Explicitly state that CMP only modifies the Status Register / condition flags, leaving register operands completely unchanged.
    Step-by-Step Worked Solutions

    Question: Trace the following AQA assembly language program to find the final value stored in register R0: MOV R0, #0 MOV R1, #3 loop: ADD R0, R0, R1 SUB R1, R1, #1 CMP R1, #0 BNE loop HALT

    1. 1.Step 1: Initialise registers from the initial setup instructions. R0 is loaded with immediate value 0 (R0 = 0), and R1 is loaded with immediate value 3 (R1 = 3).
    2. 2.Step 2: Trace Iteration 1. 'ADD R0, R0, R1' results in R0 = 0 + 3 = 3. 'SUB R1, R1, #1' decrements R1 to 2. 'CMP R1, #0' checks if R1 is 0. Since R1 is 2, the Zero flag is not set, so 'BNE loop' branches back to 'loop'.
    3. 3.Step 3: Trace Iteration 2. 'ADD R0, R0, R1' results in R0 = 3 + 2 = 5. 'SUB R1, R1, #1' decrements R1 to 1. 'CMP R1, #0' tests R1. Since R1 is 1, 'BNE loop' branches back to 'loop'.
    4. 4.Step 4: Trace Iteration 3. 'ADD R0, R0, R1' results in R0 = 5 + 1 = 6. 'SUB R1, R1, #1' decrements R1 to 0. 'CMP R1, #0' tests R1. Since R1 equals 0, the Zero flag is set (Z=1), so the 'BNE loop' branch condition fails.
    5. 5.Step 5: Execution falls through to 'HALT'. Read the final stored value in register R0.
    Final Answer: R0 = 6

    Question: Write a sequence of AQA assembly instructions to check whether the least significant bit (bit 0) of the value in R1 is 1. If it is 1, branch to the label 'odd'; otherwise, continue to 'even'.

    1. 1.Step 1: Select the appropriate bitwise logic operation. A bitwise AND operation with a mask isolates specific bits without affecting other registers.
    2. 2.Step 2: Determine the bitmask. To test bit 0, use the binary mask 00000001 (decimal 1).
    3. 3.Step 3: Apply the bitwise operation using an immediate operand: 'AND R2, R1, #1'. This leaves R2 as 1 if bit 0 was set, or 0 if bit 0 was clear.
    4. 4.Step 4: Compare the result to zero or one: 'CMP R2, #1'.
    5. 5.Step 5: Apply the branch instruction: 'BEQ odd', followed immediately by an unconditional branch or fallthrough to 'even'.
    Final Answer: AND R2, R1, #1 CMP R2, #1 BEQ odd B even
    Active Recall Memory Test
    What is the difference between immediate addressing and direct addressing?
    Key Fact: In immediate addressing, the operand value IS the actual datum to be used. In direct addressing, the operand specifies the memory address where the datum is stored.
    Which assembly instruction modifies the Status Register without changing the values in general-purpose registers?
    Key Fact: The 'CMP' (Compare) instruction.
    What mathematical effect does the instruction 'LSL R0, R0, #2' have on an unsigned integer in R0?
    Key Fact: It performs a logical shift left by 2 positions, multiplying the value in R0 by 4 (2^2).
    Which logical bitwise operator is used to toggle (invert) specific bits in a register?
    Key Fact: EOR (Exclusive OR) with a mask containing 1s at the positions to be toggled.
    Frequently Asked Questions
    What is the difference between an opcode and an operand?
    An opcode (operation code) is the portion of a machine code instruction that specifies the basic operation the CPU must perform, such as ADD, SUB, or LDR. The operand represents the data or the memory address on which the opcode operates. In machine code, both are encoded as binary bit strings.
    Why do computers use assembly language instead of just high-level languages?
    Assembly language allows direct hardware manipulation, precise timing control, and minimal memory overhead. It is indispensable for writing device drivers, real-time embedded systems, bootloaders, and operating system kernels where resource constraints and direct register manipulation make high-level language abstractions unsuitable.
    How does indirect addressing work in assembly?
    In indirect addressing, the operand specifies a memory location that contains another address, which is the actual target address where the required datum resides. It is effectively a pointer, allowing programs to navigate dynamic data structures such as linked lists and arrays.
    Do I need to memorise the exact AQA assembly instruction set for the exam?
    Yes, you must be familiar with the core AQA assembly instruction set provided in the specification (including LDR, STR, ADD, SUB, MOV, CMP, B, BEQ, BNE, AND, ORR, EOR, LSL, LSR). While a reference sheet is often included in the exam paper, knowing the mnemonics, operand order, and addressing syntax by heart saves crucial time.
    What is the difference between LDR and MOV in AQA assembly?
    MOV is primarily used to copy an immediate literal value or copy the content of one register into another register (e.g. MOV R0, #5 or MOV R0, R1). LDR (Load Register) is used to load data into a register directly from a main memory address (e.g. LDR R0, 100), crossing the system bus.