Open In App

Difference between Relative Addressing Mode and Direct Addressing Mode

Prerequisite – Addressing Modes In an Instruction Fetch operation of the Instruction Cycle Process, addressing mode plays a crucial part. Addressing Mode is how the operand is addressed in an instruction word before being executed. 

1. Relative Address Mode: In this mode, the Effective Address (EA) of the operand is calculated by adding the content of the CPU register and the address part of the instruction word. The effective address is calculated by adding displacement (immediate value given in the instruction) and the register value. The address part of the instruction is usually a signed number, either positive or negative. The effective address thus calculated is relative to the address of the next instruction.



EA = CPU Register + Displacement

Figure – PC Relative Addressing Mode



Relative Addressing Mode can be further classified into three types –

2. Direct Address Mode: In Direct Address Mode, the effective address of the operand is equal to the address part of the instruction, i.e. the address part of the instruction indicates the memory location containing the operand. Example – ADD R1, 4000 where 4000 is the effective address of the location. 

Figure – Direct Address ModeIn this example, the memory location 4000 contains the operand 100 which gets added to the contents of R1 and gets stored in R1. 
Difference between Relative Addressing Mode and Direct Addressing Mode : 

position-independent RELATIVE ADDRESSING MODE DIRECT ADDRESSING MODE
The effective address is calculated by adding the contents of the CPU Register with the address part of the instruction. The address for fetching the operand is already provided in the address part of the instruction. It is not calculated.
The relative mode has three types: PC Relative, Index Register Relative,  and Base Register Relative Addressing modes. Direct addressing mode has no types.
It results in a shorter address field in the instruction format as the relative address can be specified with a small number of bits. It results in a longer address field in the instruction format as it requires more bits to designate the entire memory address.
It is often used with branch-type instructions since it directly updates the program counter. It is not used in branch type of instructions.
It is used for writing relocatable code, and position independent code, i.e. for program relocation at run time. It is used to access static data.
It is used to implement array addressing, and records. It is used to implement variables.
It is used to handle recursive procedures. It cannot handle recursive procedures.

The PC Relative or Base Relative Addressing mode is favored over the direct addressing mode because-
i) Reduce the size of program storage.
ii) Reduce the instruction fetch queue’s size.

iii) It will be simpler to relocate.

It is less preferable to use over PC Relative or Base Relative Addressing mode.
Advantage- Flexible Advantage- Simple to use as no intermediary is involved for referencing memory.
Disadvantage- Complexity Disadvantage- Address space limit
Application- It aids in run-time program relocation and instruction sequence modification. Application- It assists in accessing static data and implementing variables.

Relative addressing mode and Direct addressing mode are two addressing modes used in computer architecture to access memory.

In Direct addressing mode, the instruction operand contains the memory address of the data being accessed. For example, the instruction MOV AX, [5000H] copies the value stored in memory location 5000H to the AX register. Direct addressing mode is simple and efficient, but has the limitation of not allowing the instruction to be relocatable.

On the other hand, in Relative addressing mode, the instruction operand specifies a memory address relative to the current instruction pointer or program counter. For example, the instruction JMP REL8 jumps to a memory address that is located at an offset of 8 bytes from the current instruction pointer. Relative addressing mode allows for relocatable code, where the program can be loaded at different memory locations without having to modify the instructions.

Here are some key differences between Relative addressing mode and Direct addressing mode:

  1. Operand: In Direct addressing mode, the operand specifies the memory address of the data being accessed, while in Relative addressing mode, the operand specifies a memory address relative to the current instruction pointer or program counter.
  2. Relocatability: Direct addressing mode does not allow for relocatable code, while Relative addressing mode allows the program to be loaded at different memory locations without modifying the instructions.
  3. Instruction size: Direct addressing mode instructions have a larger size because they include the full memory address, while Relative addressing mode instructions can use shorter operands because they only specify the offset from the current instruction pointer.
  4. Memory access: Direct addressing mode accesses memory directly, while Relative addressing mode requires an additional calculation to determine the memory address.

Overall, Relative addressing mode and Direct addressing mode are two different ways of accessing memory in computer architecture. Direct addressing mode is simpler and more efficient, but has the limitation of not allowing relocatable code, while Relative addressing mode allows for relocatable code but requires additional calculation to determine the memory address.

Article Tags :