Computing - AQA Assembly
AQA Computer Science 2022
Registers
Simple computers have an accumulator, more complex computers have…?
Registers.
Loading and storing
What does LDR Rd, (memory ref) do?
LDR Rd, (memory ref) do?Load the value stored in (memory ref) into register d.
I want to put a value at a memory address into a register. What instruction should I use?
LDR.
What does STR Rd, (memory ref) do?
STR Rd, (memory ref) do?Store the value in register d in the memory location specified by (memory ref)
I want to store what’s in a register in a memory address. What instruction should I use?
STR.
Addition and subtraction
What does ADD Rd, Rn (operand) do?
ADD Rd, Rn (operand) do?Add the value specified by (operand) to the value in register n and store the result in register d.
I want to add what’s in a memory address to a register. What instruction should I use?
ADD.
What does SUB Rd, Rn, (operand) do?
SUB Rd, Rn, (operand) do?Subtract the value specified by (operand) from Rn and store it in Rd.
I want to subtract 5 from R7 and store the result in R5. What instruction should I use?
R7 and store the result in R5. What instruction should I use?SUB R5,R7,#5
Moving values
What does MOV Rd,(operand) do?
MOV Rd,(operand) do?Move the value specified by (operand) into register Rd.
Comparison and branching
How can you do something similar to if-statements in assembly?
Using compare and branch.
What does CMP Rn,(operand) do?
CMP Rn,(operand) do?Compare the value stored in register Rn with the value specified by (operand).
I want to compare the contents of register R10 with what’s at memory address 300. What instruction should I use?
R10 with what’s at memory address 300. What instruction should I use?CMP R10,300
What does B <label> do?
B <label> do?Always branch to the instruction at position <label> in the program.
What does B<condition> <label> do?
B<condition> <label> do?Branch to <label> if the last comparison met the conditions specified by <condition>.
Loops
How can you write a while loop in assembly?
- Have a label at the start of the loop
- Write condition that branches to start if met
Logical bitwise operators
What are the instructions for the 4 logical bitwise operators?
ANDORREORMVN
What arguments do all the logical bitwise instructions take?
Rd, Rn, (operand)
What does EOR R1, R3, #5 do?
EOR R1, R3, #5 do?Perform XOR between all the bits in R3 and the number 5 and store the result in R1.
How can you test if bits are set in assembly?
- Do a bitwise
ANDwith a binary number comprised only of the bits you want to test for. - If the result is the binary number you specified, then it matches.
How can you set bits in assembly?
- Do a bitwise
ORwith a binary number comprised of only the bits you want to set.
How can you test for odd numbers using assembly?
By doing a bitwise AND with #1 and checking if the result is also #1.
I want to test if R3 is even. What are the instructions to do this?
AND R3,R3,#1
CMP R3,#1
BNE <where to go if even>