A-Level Computer Science / Unit 4: CPU Operation and Low-Level Processing

4.2.3 Addressing Modes: Indexed and Relative

πŸ”’ Lesson slides are available to signed-in users. Sign in

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.

Effective address = address operand + contents of IX

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.

AddressContents
27538
28964
30152
  1. LDX 275 supplies the address operand 275.
  2. IX contains 14, so calculate 275 + 14 = 289.
  3. Memory address 289 contains 64, so ACC receives 64.
Keep the steps separate: address operand + IX β†’ effective address β†’ memory contents loaded into ACC.

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.

Target address = base address + offset
Program baseOffsetTarget address
1200+171217
3600+173617

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.

ModeWhat the operand representsWhat happens next
ImmediateThe data valueUse the operand itself.
DirectThe address where the data is storedRead the contents at that address.
IndirectThe address of a location containing another addressFollow the second address to obtain the data.
IndexedAn address operandAdd the contents of IX to it to form the effective address, then read the contents there.
RelativeAn offset from a base addressAdd the offset to the base to find the target address.
Useful contrast: indexed addressing adds IX to an address operand to locate data. Relative addressing adds an offset to a base address to locate a target.

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.

ADDRESS CALCULATOR

Choose an addressing mode

Ready

Values for this example

Choose Indexed or Relative.

Address operand275
IX contents14
Program base1200
Relative offset+17

Memory table

AddressContents
27538
28964
30152
Choose a mode to begin.
Base / operandβ€”
IX / offsetβ€”
Calculated addressβ€”
Data at addressβ€”

Identify the parts

Choose an addressing mode to see how the address is calculated.

An effective address is used to access memory. A relative target address identifies the target from the program base.

5. Avoid these common mix-ups

Mix-upCorrect explanation
Adding memory contents to IXAdd the address operand to the contents of IX to calculate the effective address.
Calling the effective address the data valueThe effective address identifies a memory location. Read its contents to obtain the data.
Calling the relative offset the target addressThe target address is the base address plus the offset.
Changing the offset when a program movesThe base changes after relocation; the relative offset can remain the same.

6. Check your understanding

Try each question before opening the suggested response.

  1. An instruction has address operand 275. IX contains 14. Calculate the effective address.
    Suggested response

    275 + 14 = 289. The effective address is 289.

  2. The effective address is 289 and memory location 289 contains 64. What is loaded into ACC?
    Suggested response

    64, because ACC receives the contents at the effective address.

  3. A program has base address 1200 and relative offset +17. Find the target address.
    Suggested response

    1200 + 17 = 1217.

  4. 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.

  5. 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.