AQA A-Level Computer Science AS Paper 2, June 2025: Question 10
5 marks · Hard difficulty · Programming
Complete an assembly language instruction using immediate addressing and write an assembly language program to calculate the nth triangular number.
Practise this questionQuestion
Question text
10.1 An assembly language program contains an instruction that loads the integer value 13
into register R1.
Complete the missing part of the instruction.
[1 mark]
MOV R116, …
10.2 Triangular numbers are numbers that count the number of objects that would appear
when arranged in an equilateral triangle.
The sequence of triangular numbers starts with 1 and proceeds in order. The first five
triangular numbers are 1, 3, 6, 10, and 15. The diagram in Figure 4 shows the first
five triangular numbers.
Figure 4
Complete the assembly language program below to calculate the nth triangular
number. The value of n has already been stored in register R0. The program should
store the nth triangular number in register R1.
Write one instruction per line. You may not need to use all lines for your solution.
[4 marks]
Mark scheme
Show the mark scheme
10 1 Mark is for AO1 (understanding) 1
#13;
R. 13 – – –
Qu Pt Marking Guidance Marks
10 2 Marks are for AO3 (programming) 4
1 mark: Changing the values of two registers
1 mark: Use of ADD/SUB to increment/decrement register used as a loop counter
1 mark: Correct logic for a loop that iterates n or n + 1 times
1 mark: Correct calculation of nth triangular number and storing in register R1.
Max 3 if any errors
Example solution 1
MOV R1, #0
MOV R2, #0
loopstart:
ADD R1, R1, #1
ADD R2, R2, R1
CMP R1, R0
BLT loopstart
MOV R1, R2
HALT
Example solution 2
MOV R1, #0
loop:
ADD R1, R1, R0
SUB R0, R0, #1
CMP R0, #0
BNE loop
HALT
n (n + 1)
Example solution 3: formula
MOV R2, #0
ADD R1, R0, #1
loopstart:
ADD R2, R2, R1
SUB R0, R0, #1
CMP R0, #0
BNE loopstart
LSR R2, R2, #1
MOV R1, R2
HALT
How to answer it
Assembly Language Programming & Immediate Addressing
AQA AS Level Computer Science — Paper 2 Architecture & Assembly Instruction Set
Core Architecture & Low-Level Programming Skills:
- Addressing Modes: Identifying immediate addressing syntax ( # ) vs. direct memory addressing.
- Algorithmic Assembly Logic: Implementing iterative algorithms (accumulators and countdown loops) using standard AQA assembly operations.
- Register Operations: Loading ( MOV ), arithmetic ( ADD , SUB ), comparisons ( CMP ), conditional branching ( BNE , BLT ), and machine halt ( HALT ).
Loading an Immediate Value into a Register
Completing the assembly instruction to load the integer 13 into register R1 [1 Mark]
✅ Correct Answer
#13
Full instruction: MOV R1, #13
💡 Key Knowledge: Addressing Modes
- Immediate Addressing ( #value ): The operand is the actual numerical value to be used.
- Direct Addressing ( memory_address ): The operand is a memory address from which the data must be fetched.
- In AQA assembly, omitting the # turns the operand into a direct memory reference.
❌ Common Errors & Examiner Traps
- Writing 13 without the hash symbol: The mark scheme explicitly states "R. 13" (Reject 13). Without # , the CPU attempts to load the contents of memory address 13 rather than the literal integer 13.
- Writing register syntax: Confusing the immediate value with another register (e.g. writing R13 ).
🧠 Exam Technique
Always inspect the instruction requirements: if asked to load a constant or integer literal directly into a register, you must prefix the number with # .
Calculating the nth Triangular Number
Writing a multi-instruction assembly loop to accumulate a sequence sum [4 Marks]
💡 Mathematical Concept
The nth triangular number is the sum of integers from 1 up to n:
T(n) = 1 + 2 + 3 + ... + n
Since register R0 already holds n, the most efficient approach is a countdown accumulator loop adding R0 to an accumulator R1 , decrementing R0 each iteration until it reaches 0.
✅ Model Solution (Countdown Loop)
MOV R1, #0 loop: ADD R1, R1, R0 SUB R0, R0, #1 CMP R0, #0 BNE loop HALTAlternative approach: Count up from 1 to n using a second counter register.
📐 Step-by-Step Logic Trace (e.g. n = 4)
Target: 4th triangular number = 1 + 2 + 3 + 4 = 10.
| Step | Instruction | R0 (Counter) | R1 (Accumulator) |
|---|---|---|---|
| Start | MOV R1, #0 | 4 | 0 |
| Pass 1 | ADD then SUB | 3 | 4 |
| Pass 2 | ADD then SUB | 2 | 7 |
| Pass 3 | ADD then SUB | 1 | 9 |
| Pass 4 | ADD then SUB | 0 | 10 |
| End | CMP / BNE / HALT | 0 | 10 (Correct) |
🧠 Mark Scheme Breakdown (4 Marks AO3)
- Mark 1: Changing the values of two registers (e.g. initialising accumulator and updating loop values).
- Mark 2: Use of ADD or SUB to increment or decrement the register used as a loop counter.
- Mark 3: Correct logic for a loop iterating n or n + 1 times (correct label and branch condition).
- Mark 4: Correct calculation of the nth triangular number and storing it in register R1 .
❌ Common Errors to Avoid
- Failing to initialise the accumulator: Assuming R1 starts at 0 without executing MOV R1, #0 .
- Off-by-one loop errors: Exiting when counter is 1 instead of 0, or testing condition in the wrong place, leading to sums like 4 + 3 + 2 = 9.
- Missing the # prefix on constants: Writing SUB R0, R0, 1 or MOV R1, 0 instead of #1 and #0 .
- Forgetting HALT : In low-level assembly, failing to stop execution causes the processor to execute unintended subsequent memory instructions.
✅ Alternative Count-Up Method (Solution 1 in Mark Scheme)
MOV R1, #0 ; Counter (1 to n) MOV R2, #0 ; Accumulator loop: ADD R1, R1, #1 ; Next number ADD R2, R2, R1 ; Add to sum CMP R1, R0 ; Reached n? BLT loop ; If R1 < R0, branch MOV R1, R2 ; Move final result to R1 HALTTopics
4.7 Fundamentals of computer organisation and architecture · 4.7.3 Structure and role of the processor and its components
Question and mark scheme from the AQA A-Level Computer Science examination, AS Paper 2, June 2025. QuestionVault is an independent revision resource; questions remain the copyright of the awarding body.