AQA A-Level Computer Science Paper 2, June 2025: Question 14
6 marks · Hard difficulty · Short Answer
Explain the purpose of sections 2 to 6 of an assembly language program controlling a robot's motors and sensors via an 8-bit memory-mapped I/O location.
Practise this questionQuestion
Question text
14 An assembly language program is used to control the operation of a robot.
The program uses the AQA assembly language instruction set in Table 3 on page 36.
The value in memory location 100 is used to read input from the robot’s sensors and
to provide output to the robot’s motors. The memory location can hold an 8-bit value.
Figure 9 shows an example 8-bit value in memory location 100.
Figure 9
Outputs Inputs
B7 B6 B5 B4 B3 B2 B1 B0
11 0 1 0 0 1 0
The purpose of each bit is:
• B7 – Controls the motor that drives the robot’s left wheel.
• B6 – Controls the motor that drives the robot’s right wheel.
• B5 – Controls the motor that drives the robot’s accessory arm.
• B4 – Represents the input from an ultrasonic sensor.
• B3 – Represents the input from a light sensor.
• B2 – Represents the input from touch sensor X.
• B1 – Represents the input from touch sensor Y.
• B0 – Represents the input from touch sensor Z.
Writing a value of 1 to one of the bits B7 to B5 will cause the motor controlled by the
bit to turn on. The motor will remain on until a 0 is written to the bit.
Reading a value of 1 from bits B4 to B0 indicates that the sensor associated with the
bit has been activated. Reading a value of 0 indicates that the sensor has not been
activated.
For example, the value 11010010 in memory location 100 in Figure 9 indicates that
the robot is driving forward, as both the left and right motors are on, and that the
ultrasonic sensor and touch sensor Y have been activated.
The current state of the inputs can be determined by reading the value from memory
location 100. When a value is written to memory location 100, only the values in bits
B7 to B5 change.
The program in Table 2 is used to make the robot carry out a task. The program has
been split into six sections.
Complete the Purpose column of Table 2 to explain the effect of the code in
sections 2 to 6 on the robot. In your response, where appropriate, you
should include the effect of the sensor inputs on the robot’s actions.
[6 marks]
Table 2
Section Code Purpose
1 LDR R0, 100 Make the robot drive forwards.
ORR R0, R0, #192
STR R0, 100
2 loop1:
LDR R0, 100
AND R1, R0, #7
CMP R1, #0
BEQ loop1
3 LDR R0, 100
AND R0, R0, #63
STR R0, 100
4 LDR R0, 100
MOV R2, #0
MOV R3, #0
loop2:
AND R1, R0, #1
CMP R1, #0
BEQ skip
ADD R2, R2, #1
skip:
ADD R3, R3, #1
LSR R0, R0, #1
CMP R3, #3
BNE loop2
CMP R2, #2
BEQ active
HALT
5 active:
LDR R0, 100
ORR R0, R0, #32
STR R0, 100
6 loop3:
LDR R0, 100
AND R1, R0, #8
CMP R1, #0
BEQ loop3
AND R0, R0, #223
STR R0, 100
HALT 36
Table 3 – Standard AQA assembly language instruction set
LDR Rd, <memory ref> Load the value stored in the memory location specified by
<memory ref> into register d
STR Rd, <memory ref>*35* Store the value that is in register d into the memory location
specified by <memory ref>
ADD Rd, Rn, <operand2> Add the value specified in <operand2> to the value in
register n and store the result in register d
SUB Rd, Rn, <operand2> Subtract the value specified by <operand2> from the value
in register n and store the result in register d
MOV Rd, <operand2> Copy the value specified by <operand2> into register d
CMP Rn, <operand2> Compare the value stored in register n with the value
specified by <operand2>
B <label> Always branch to the instruction at position <label> in
the program.
B<condition> <label> Branch to the instruction at position <label> if the last
comparison met the criterion specified by <condition>.
Possible values for <condition> and their meanings are:
EQ: equal to NE: not equal to
GT: greater than LT: less than
AND Rd, Rn, <operand2> Perform a bitwise logical AND operation between the value
in register n and the value specified by <operand2> and
store the result in register d
ORR Rd, Rn, <operand2> Perform a bitwise logical OR operation between the value in
register n and the value specified by <operand2> and store
the result in register d
EOR Rd, Rn, <operand2> Perform a bitwise logical XOR (exclusive or) operation
between the value in register n and the value specified by
<operand2> and store the result in register d
MVN Rd, <operand2> Perform a bitwise logical NOT operation on the value
specified by <operand2> and store the result in register d
LSL Rd, Rn, <operand2> Logically shift left the value stored in register n by the
number of bits specified by <operand2> and store the result
in register d
LSR Rd, Rn, <operand2> Logically shift right the value stored in register n by the
number of bits specified by <operand2> and store the result
in register d
HALT Stops the execution of the program.
Labels: A label is placed in the code by writing an identifier followed by a colon (:). To refer to a
label, the identifier of the label is placed after the branch instruction.
Interpretation of <operand2>
<operand2> can be interpreted in two different ways, depending on whether the first character
is a # or an R:
• # – use the decimal value specified after the #, eg #25 means use the decimal value 25
• Rm – use the value stored in register m, eg R6 means use the value stored in register 6
Mark scheme
Show the mark scheme
Total
Qu Pt Marking guidance
marks
14 Marks are AO2 (analyse) 6
Section Purpose
2 Keep going forward / wait / loop until a touch sensor / (at least) one
of sensors X, Y or Z is activated // keep going forward / wait / loop if
no touch sensors / none of sensors X, Y or Z are activated;
A. check if (at least) one / any of sensors X, Y or Z // any of the
touch sensors are activated
3 Stop the robot moving (forward);
A. stop (both) the motors
41 mark: Count how many touch sensors // count how many of
sensors X, Y and Z are activated;
1 mark: End the program (A. stop) if the number of active (touch)
sensors is not 2 / is 1 or 3 (A. 0, 1 or 3);
OR
2 marks: End the program (A. stop) if the number of active touch
sensors is not 2 / is 1 or 3 (A. 0, 1 or 3) // end the program (A. stop)
if the number of sensors X, Y and Z that are on is not 2 / is 1 or 3
(A. 0, 1 or 3);;
NE. stop the robot for end the program
5 Turn on / move the (robot accessory) arm;
6 Keep the arm moving until the light sensor is activated // stop the
arm when the light sensor is activated // wait until the light sensor is
activated then stop the arm;
For all sections, accept sensor being on or sensor having a value of 1
instead of sensor activated and accept sensor being off or sensor having a
value of 0 instead of sensor deactivated.
For sections 2 3, 5 and 6, do not award mark if any additional purposes are
described which are incorrect.
For section 4, Max 1 if any additional purposes are described which are
incorrect but ignore descriptions relating to continuation of something that
is already happening.
Ignore lower level descriptions of code such as ‘Add one onto R3’,
‘Shift R0 right’ etc
How to answer it
Assembly Language Bit Manipulation & Robot Control
This question assesses your ability to analyse standard AQA assembly language in an embedded systems / hardware control context (AO2 - Analysis). Specifically, it evaluates:
- Bitwise masking (AND): Isolating specific sensor input bits or clearing output control bits.
- Bitwise setting (ORR): Turning on specific actuator output bits without altering others.
- Logical shifts & loop tracing (LSR): Iterating through bit positions to inspect individual binary flags.
- High-level hardware intent: Translating low-level register operations into concrete robot actions (e.g. stopping motors, awaiting sensor thresholds) rather than just paraphrasing code line by line.
| Outputs (Actuators) | Inputs (Sensors) | ||||||
|---|---|---|---|---|---|---|---|
| B₇ | B₆ | B₅ | B₄ | B₃ | B₂ | B₁ | B₀ |
| Left Wheel | Right Wheel | Accessory Arm | Ultrasonic | Light | Touch X | Touch Y | Touch Z |
Section 2: Polling the Touch Sensors
Code: loop1: LDR R0, 100 | AND R1, R0, #7 | CMP R1, #0 | BEQ loop1
✅ Correct Purpose (1 Mark)
Any of the following answers achieves full credit:
- Keep going forward / wait / loop until a touch sensor (or at least one of sensors X, Y, or Z) is activated.
- Keep going forward / wait / loop while no touch sensors are activated.
- Check if at least one of touch sensors X, Y, or Z is activated.
📐 Bit Tracing
- Operand is decimal #7 = binary 00000111₂ .
- Performing AND R1, R0, #7 masks out bits B₇–B₃, isolating only bits B₂ (X), B₁ (Y), and B₀ (Z).
- If none of these sensors are active, the result in R1 is 0.
- BEQ loop1 branches back while R1 == 0 . Once any touch sensor reads 1, the branch fails and execution continues.
🧠 Exam Technique
Remember that Section 1 already turned the motors on to drive forward. Because this section does not change the outputs, the physical robot continues doing what it was doing—driving forward—while waiting for the input.
❌ Common Errors
- Literal description: Writing "Performs an AND with 7 and branches if zero" scores 0 marks. Examiners demand the physical effect on the robot.
- Omission of sensors: Saying "Wait until a sensor is pressed" without specifying touch sensor or X, Y, Z is insufficient.
Section 3: Stopping the Drive Motors
Code: LDR R0, 100 | AND R0, R0, #63 | STR R0, 100
✅ Correct Purpose (1 Mark)
- Stop the robot moving (forward).
- Stop both wheel motors / turn off left and right motors.
📐 Bit Tracing
- Decimal #63 = binary 00111111₂ .
- Bitwise AND with 00111111₂ forces bits B₇ and B₆ to 0 .
- Bits B₅ through B₀ remain completely unchanged.
- Because B₇ (left wheel) and B₆ (right wheel) are set to 0, both drive motors stop.
💡 Key Knowledge: Bit Clearing Mask
To turn off specific bits while preserving all other bits, apply a bitwise AND using a mask that contains 0 at the target bit positions and 1 everywhere else.
❌ Common Errors
Claiming this turns off all robot components or resets all sensors. Inputs cannot be cleared by writing to memory location 100 (the preamble states only B₇–B₅ change upon writing), and bit B₅ is already 0.
Section 4: Counting Active Touch Sensors
Code: Bit inspection loop ( loop2 ) shifting right with LSR
✅ Correct Purpose (2 Marks)
1 mark: Count how many touch sensors (sensors X, Y, and Z) are activated.
1 mark: End the program / stop execution if the number of active touch sensors is not 2 (i.e. is 0, 1, or 3) [OR: continue to activate arm only if exactly 2 are active].
(Both points stated together award 2 marks directly).
📐 Step-by-Step Register Trace
- R2 is initialised to 0 (counter of activated sensors).
- R3 is initialised to 0 (loop iteration counter).
- AND R1, R0, #1 isolates the lowest bit (B₀ initially). If set, increment R2 .
- LSR R0, R0, #1 shifts all bits right by 1 position (B₁ moves into B₀, B₂ into B₁, etc.).
- The loop executes exactly 3 times ( CMP R3, #3 ), testing B₀, B₁, and B₂.
- Finally: CMP R2, #2 followed by BEQ active . If R2 == 2 , it jumps to active . Otherwise, it hits HALT .
🧠 Exam Technique: Identifying Nested Logic
Whenever you see a combination of a counter register ( ADD R2, R2, #1 ), a loop counter ( CMP R3, #3 ), and LSR , recognise this standard assembly idiom: tallying the number of set bits (Hamming weight) across a subfield.
❌ Common Errors & Examiner Warnings
- Not Enough (NE): Saying "Stop the robot" instead of "End/halt the program" scores no mark for the second point, because the motors were already halted in Section 3!
- Vagueness: Stating "Checks if touch sensors are on" without mentioning that it specifically checks for exactly 2 active sensors misses the second mark.
Section 5: Activating the Accessory Arm
Code: active: LDR R0, 100 | ORR R0, R0, #32 | STR R0, 100
✅ Correct Purpose (1 Mark)
- Turn on the robot accessory arm.
- Move / start the robot accessory arm motor.
📐 Bit Tracing
- Decimal #32 = binary 00100000₂ .
- Bit 5 (B₅) controls the accessory arm motor.
- ORR R0, R0, #32 performs a bitwise logical OR, forcing bit B₅ to 1 while leaving every other bit completely untouched.
- Writing the value back ( STR R0, 100 ) energises the accessory arm.
💡 Key Knowledge: Bit Setting Mask
To turn on specific hardware outputs without disturbing the rest of the register state, use a bitwise ORR with a mask containing a 1 at the target bit position and 0 everywhere else.
❌ Common Errors
Confusing bit numbering: 2⁵ = 32 corresponds to bit B₅ (the 6th bit from the right, starting at index 0). Misidentifying B₅ as the ultrasonic sensor (B₄) or right motor (B₆) results in zero marks.
Section 6: Waiting for Light Sensor & Arm Shutdown
Code: Polling loop on #8 , then AND R0, R0, #223 followed by HALT
✅ Correct Purpose (1 Mark)
Any of the following descriptions achieves the mark:
- Keep the arm moving until the light sensor is activated.
- Stop the arm when the light sensor is activated.
- Wait until the light sensor is activated, then stop the arm (and end program).
📐 Bit Tracing
- AND R1, R0, #8 : Decimal #8 = 00001000₂ (isolates B₃ = Light sensor).
- BEQ loop3 : Loops continuously while B₃ is 0 (light sensor inactive).
- Once light sensor triggers (B₃ becomes 1), loop exits.
- AND R0, R0, #223 : Decimal #223 = 11011111₂ (255 − 32). This clears bit B₅ to 0, switching off the arm motor.
- HALT terminates the program.
🧠 Exam Technique: Holistic Event Summary
Notice the two-part structure of this section: a condition wait (polling) followed by an action (shutoff). High-scoring responses link cause and effect: "When [sensor input happens], do [actuator action]."
❌ Common Errors
- Omitting the light sensor entirely and just saying "Stop the arm after a delay".
- Stating that the robot stops moving forward (the wheels were already stopped in Section 3).
Topics
4.7 Fundamentals of computer organisation and architecture · 4.4 Theory of computation · 4.1 Fundamentals of programming · 4.7.3 Structure and role of the processor and its components · 4.4.1 Abstraction and automation · 4.1.1 Programming
Question and mark scheme from the AQA A-Level Computer Science examination, Paper 2, June 2025. QuestionVault is an independent revision resource; questions remain the copyright of the awarding body.