Question 14
AQA Computer Science June 2025 Paper 2 (7517/2)A level6 marks
On the specification
- 4.7 Fundamentals of computer organisation and architecture
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 box 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 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> 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