Computer architecture · A level · OCR H446 1.2.4, AQA 7517 4.7.3.5 · about 25 min
AQA's instruction set, compare and branch, masks and shifts, and the bit fields that drive BugBot's motors.
[1 mark]What is the difference between MOV R1, #50 and LDR R1, 50?
[1 mark]What does this program print?
r0 = 0b11001010 print(format(r0 & 0b00001111, '08b')) print(format(r0 | 0b00000001, '08b')) print(format(r0 >> 3, '08b'))
[1 mark]R0 holds 13. What does R1 hold after LSL R1, R0, #2?
[1 mark]Which instruction toggles (flips) the lowest four bits of R2, leaving the others alone?
[1 mark]A program does CMP R0, #10 then BLT small. When does it branch?
[1 mark]Why does an if-else in AQA assembly need an unconditional B after the 'if' part?
commands holds four motor control bytes, each a whole number from 0 to 255 laid out as in the table above. For each byte, use bitwise operators (>> and &) to split it into its speed (0 to 63) and its mode, and:
- print a line in the form 161: speed 40 forward: the byte in denary, the speed, then the mode as coast, forward, reverse or brake;
- then act on it: forward drives forward 10 cm at that speed, reverse drives backward 10 cm at that speed, brake calls stop(), and coast does nothing.
Do not convert the byte to a string of bits.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() commands = [161, 98, 3, 0] modes = ["coast", "forward", "reverse", "brake"]
Plan your program here, then type it in and press Run.