CIE AS & A Level Computer Science, section 4.2 (Assembly language)
Addressing modes
The addressing mode says how the operand is used to find the data.
Immediate addressing
The operand is the value to use. No memory access is needed.
LDM #5 loads the number 5 into ACC.
Direct addressing
The operand is the address of the data.
LDD 200 loads the contents of address 200 into ACC. If address 200 holds 40, ACC becomes 40.
Indirect addressing
The operand is the address of a location that contains the address of the data.
LDI 201: address 201 holds 300, and address 300 holds 77. ACC becomes 77.
Indexed addressing
The address is formed by adding the contents of the index register (IX) to the operand.
LDX 200 with IX = 3 reads from address . Changing IX steps through consecutive locations, such as the elements of an array.
Relative addressing
The address is found by adding the operand to the current address (the PC). For example, a jump of goes to five locations after the current instruction. It makes the program relocatable: it works wherever it is loaded in memory.
| Mode | Operand means | Example |
|---|---|---|
| Immediate | the value itself | LDM #5 |
| Direct | the address of the data | LDD 200 |
| Indirect | address of the address of the data | LDI 201 |
| Indexed | address + IX | LDX 200 |
| Relative | offset from the current instruction | relative jump |
Choosing a mode
Use immediate for constants, direct for single variables, indexed to process arrays, and indirect for pointers.
Common mistake: mixing up immediate and direct addressing. LDM #5 loads the number 5; LDD 5 loads the contents of address 5. Also, for indirect addressing there are two memory accesses to follow.
Exam tip: when asked what a value is after an instruction, draw the memory table and follow the addresses step by step. For indexed addressing, always add IX to the operand first.
Check yourself
Address 200 holds 40. What does `LDD 200` put in ACC?
IX holds 3. From which address does `LDX 200` load?
.
Which addressing mode uses the operand as the actual data value?
Immediate addressing.