Indexed and Relative Addressing
Indexed addressing calculates an effective address by adding the address operand to the contents of the Index Register (IX). Relative addressing uses an offset from a base address to calculate a target address.
By the end of this page, you should be able to:
- calculate an effective address using indexed addressing;
- use the effective address to find the data loaded into ACC;
- explain relative addressing using a base address and an offset;
- explain why relative addressing helps when a program is relocated;
- compare all five addressing modes.
1. Indexed addressing calculates an effective address
With indexed addressing, the processor adds the address operand to the contents of IX. The result is the effective address: the actual memory address used to access the data.
For example, an instruction has address operand 275 and IX contains 14.
The effective address is 275 + 14 = 289. The effective address is an address, not the
data stored at that address.
Add the address operand and IX
Do not add IX to the memory contents. First calculate the effective address. Then use that address to read the value from memory.
2. Read the data at the effective address
After calculating the effective address, the processor accesses that memory location. ACC receives the contents stored there.
| Address | Contents |
|---|---|
| 275 | 38 |
| 289 | 64 |
| 301 | 52 |
LDX 275supplies the address operand275.- IX contains
14, so calculate275 + 14 = 289. - Memory address
289contains64, so ACC receives64.
3. Relative addressing uses a base and an offset
With relative addressing, the operand represents an offset: the distance from a base address to a target. Add the offset to the base address to find the target address.
| Program base | Offset | Target address |
|---|---|---|
| 1200 | +17 | 1217 |
| 3600 | +17 | 3617 |
If the program moves, its base address changes. The offset can stay the same, so adding it to the new base finds the corresponding target in the relocated program.
The offset is not the target address
The operand is the distance from the base. The target address is the result of adding the offset to that base.
4. Compare all five addressing modes
Ask what the operand means first. Then decide how the value or target is found.
| Mode | What the operand represents | What happens next |
|---|---|---|
| Immediate | The data value | Use the operand itself. |
| Direct | The address where the data is stored | Read the contents at that address. |
| Indirect | The address of a location containing another address | Follow the second address to obtain the data. |
| Indexed | An address operand | Add the contents of IX to it to form the effective address, then read the contents there. |
| Relative | An offset from a base address | Add the offset to the base to find the target address. |
Interactive: calculate an address
Select indexed or relative addressing and move through the calculation. The widget uses fresh values. For indexed addressing, it also shows the memory lookup after the effective address is found.
5. Avoid these common mix-ups
| Mix-up | Correct explanation |
|---|---|
| Adding memory contents to IX | Add the address operand to the contents of IX to calculate the effective address. |
| Calling the effective address the data value | The effective address identifies a memory location. Read its contents to obtain the data. |
| Calling the relative offset the target address | The target address is the base address plus the offset. |
| Changing the offset when a program moves | The base changes after relocation; the relative offset can remain the same. |
6. Check your understanding
Try each question before opening the suggested response.
-
An instruction has address operand
275. IX contains14. Calculate the effective address.Suggested response
275 + 14 = 289. The effective address is289. -
The effective address is
289and memory location289contains64. What is loaded into ACC?Suggested response
64, because ACC receives the contents at the effective address. -
A program has base address
1200and relative offset+17. Find the target address.Suggested response
1200 + 17 = 1217. -
The program is relocated to base address
3600. The offset remains+17. What is the new target address?Suggested response
3600 + 17 = 3617. The same relative distance identifies the corresponding target from the new base. -
State one difference between indexed and relative addressing.
Suggested response
Indexed addressing adds the contents of IX to an address operand to form an effective address. Relative addressing adds an offset to a base address to find a target address.
Final check
For indexed addressing, show the addition, name the effective address, then state the memory contents loaded into ACC. For relative addressing, identify the base and offset, then calculate the target address.