When writing code that might be loaded at different memory addresses (position-independent code), we can’t use fixed addresses for jumps and branches. We need addresses relative to the current instruction.
Relative Addressing computes the target address by adding an offset to the Program Counter (PC). The address is relative to the current instruction, making code position-independent.
- Instruction specifies an offset value (positive or negative)
- CPU reads current PC (address of current instruction)
- Target address = PC + offset
- Used primarily for branch and jump instructions
- Example:
JMP 10— jumps to address (PC + 10)
- Position-independent: code works at any load address
- Offset is typically small (short jumps) or large (long jumps)
- Used for conditional/unconditional branches, function calls
- Most common addressing mode for control flow instructions
- Built from: Addressing Mode, Program Counter
- Related: Branch Instruction, Jump Instruction
- Contrasts with: Direct Addressing — fixed address, not relative
- Builds into: Loop, Function Call
- Offset range is limited (can’t jump too far with short relative)
- PC value used is typically after instruction fetch (PC = next instruction)
- Negative offsets for backward jumps (loops)