Loading...
Read the instruction’s destination and source operands carefully. A register number, a literal value and the contents of a memory address are three different things.
What you'll be able to do
Pearson’s assembly appendix uses a subset of ARMlite, a simplified 32-bit Arm-like machine. Work with its thirteen general-purpose registers R0 through R12, rather than assuming one accumulator. A mnemonic such as ADD is a readable instruction name; the opcode identifies the operation in the machine instruction, while operands specify the relevant registers, immediate value or address.
In MOV R0,#7, #7 is an immediate value placed into R0. MOV R1,R0 copies the current register value without clearing R0. In ADD R2,R0,R1, R2 is the destination and the other operands supply values to add. Use the supplied instruction-set reference, since different assembly languages can order operands differently. A label names a code or data location; its definition ends with a colon.
LDR R0,256 loads the word stored at byte address 256. It does not put the number 256 into the register. STR R1,260 stores the current value of R1 at byte address 260; it does not store the register’s name or address. Direct addressing names the memory location in the instruction, while immediate addressing supplies a literal value with # where the instruction permits it.
ARMlite addresses bytes, and a 32-bit word occupies four bytes. Word loads/stores require an address divisible by four, so 256 and 260 are adjacent aligned word starts. This byte-address detail prevents accidentally treating a displayed memory row as four independent word addresses one byte apart. Pearson’s appendix focuses on immediate and direct addressing; bracketed register-indirect extensions are unnecessary for the examples here.
The original program below assumes memory word 256 initially contains 7 and word 260 initially contains 0. The load gives R0=7, MOV gives R1=5, ADD gives R2=12 and SUB gives R2=10. STR writes 10 into memory at 260. HALT stops execution; it does not print a register automatically. A trace should record only the fields actually changed at each step.
Registers and memory hold fixed-width bit patterns. These small non-negative arithmetic examples avoid overflow, so ordinary denary arithmetic suffices to check them. For a wider-range question, state signed interpretation and width rather than assuming Python-style unlimited integers. Comments beginning with a semicolon explain intent and are not executed. Keeping source values alongside the changed destination makes accidental operand reversal easier to catch.
; Initial memory: word at byte address 256 is 7; word at 260 is 0.
LDR R0, 256
MOV R1, #5
ADD R2, R0, R1
SUB R2, R2, #2
STR R2, 260
HALTScroll horizontally to see the full code or table.| Instruction | Changed state |
|---|---|
| LDR R0,256 | R0 becomes 7 |
| MOV R1,#5 | R1 becomes 5 |
| ADD R2,R0,R1 | R2 becomes 12 |
| SUB R2,R2,#2 | R2 becomes 10 |
| STR R2,260 | Memory word 260 becomes 10 |
Attempt the task before opening its worked response. Record each change of state, explain the rule used, and check the result against the original requirements. Code examples labelled Python 3 use that language’s conventions; pseudocode states its own assumptions.
Common mistakes to avoid
Key takeaways
Test yourself
Answer a few questions, then review anything you missed.
Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.