Assembly and addressing modes
Reading an ARM assembly program, its labels, mnemonics and directives, recognising the five addressing modes and translating a condition or a loop into comparisons and jumps.
- 25 cards
- 4 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- Scenarios
A few cards from the deck
Mnemonic: what is it?
Show the answer
The short readable name of a machine instruction, such as ADD or LDR, which the assembler replaces with its binary code.
Each mnemonic matches one opcode of the processor: the assembler translates line by line, without optimising anything.
R1 holds 0x2000. At which address does this instruction read?
```arm
LDR R0, [R1, #4]`- 0x2004
- 0x2000
- 0x2010
- 0x0004
Show the answer
0x2004
The address is R1 + 4 = 0x2004. The value of R1 is not changed. 0x2000 forgets the offset, 0x0004 forgets the register, 0x2010 multiplies the offset by the size of a word when it already counts bytes.
In LDR R0, [R1], register R1 holds an …: this is … addressing through a register.
Show the answer
In LDR R0, [R1], register R1 holds an address: this is indirect addressing through a register.
The brackets mean “the memory cell whose address is in”. It is the mechanism behind pointers: R1 plays p, R0 receives *p.
Label: what is it?
Show the answer
A name followed by a colon, placed before a line, that stands for the address of that line and serves as a jump target or as a way to reach data.
You write BNE loop instead of a numeric address: the assembler computes the distance once the program is laid out in memory.
This loop should run ten times, but it never stops. Which fix repairs it?
```arm
MOV R1, #0
boucle:
CMP R1, #10
BLT boucle`- Replace BLT with BGE so that the test goes the other way
- Add ADD R1, R1, #1 before the CMP so that R1 progresses
- Move the label boucle above MOV R1, #0 so everything starts over
- Replace BLT with BLE so that the loop stops at 10 included
Show the answer
Add ADD R1, R1, #1 before the CMP so that R1 progresses
R1 stays at 0: CMP R1, #10 always says “smaller” and BLT always goes back to the start. A loop must change the variable its condition tests. BGE would leave at once, without a single pass; BLE would still loop forever, since R1 never moves; moving the label up would reset R1 to 0 on every pass.