Direct and indirect addressing modes are the different types of addressing modes which specifies the way of accessing the data from the memory while executing the instructions. The prior difference between the direct and indirect addressing mode is that in direct mode the address field refers directly to the memory location at which the data is stored. As against, in the indirect mode, the address field refers to the register first, which is then directed to the memory location.
What is an addressing mode?
It is a technique to determine the operand of an instruction. The main function of the microprocessor is to execute a group of instructions stored in the memory to conduct a specific task.
What does an operation require?
There are two things an operation requires – opcode and operand. For example, if we wish to subtract two numbers x and y then the two numbers will be the operands and minus (-) or subtract sign is the operator.
Content: Direct Addressing Vs Indirect addressing
|Basis for comparison||Direct Addressing||Indirect Addressing|
|Basic||Contains the actual operand in the address field of the instruction code.||The address field of the instruction holds the address of the operand.|
|Number of memory references required||Two||Three|
|Amount of address space||Small||Large|
|Additional calculation||Not required||Is the only way to perform the operation.|
Definition of Direct Addressing
The name Direct addressing itself makes clear that it does not involve any medium for accessing the data from memory. It is the most straightforward method of addressing, where the address field holds the effective address operand.
EA = A
Here, the actual (effective address) is denoted by ‘EA’ which is the location comprising the referenced operand while ‘A’ designates the contents of an address field belonging to the instruction.
What is an Effective address?
The effective address is a 32-bit address computed by the processor at the time executing the branch instruction, memory access or while retrieving the next sequential instruction. The effective address calculations regarding data and instruction retrieval employs 32-bit unsigned binary arithmetic.
However, the direct method is not generally used nowadays, as it is a traditional method. It is simple, needs just one memory reference and no additional calculations.
Let’s take an example of an instruction where the data is moving from one location to another. So, the instruction MOV A, R1 in the microprocessor transfers the contents of register 1 into the accumulator.
Definition of Indirect Addressing
In the direct addressing mode, the address field requires less word space, therefore restricting the address range. So, one of the ways is to have the address field referring the address of a word in memory, in order to hold a full-length address of the operand. This is known as indirect addressing. In simple words, this addressing mode uses a register to contain the actual address where the data is stored.
EA = (A)
Here, ‘A’ inside the parenthesis designates the “contents of A”, and EA is the effective address.
The primary merit of this approach is that it provides an address space of 2N for a word length of N. The Word Length is the number of bits in a word. Although, the address space has been increased in this method but it needs two memory references to retrieve the particular operand. One reference utilized for its address and the other one for getting its value.
For example, we have registers R0 and R1 as an eight-bit index and DPTR (Data pointer) as a 16-bit index. The symbol used for performing indirect addressing is the “@” (at sign). As shown in the diagram, the instruction MOV A, @R0 transfers the contents of the memory location whose address is stored in R0 into the accumulator. In the example, the value of the accumulator is 07H.
Using an offset, this addressing mode can also be extended for accessing the data structure in the data space memory. However, the extended version of the indirect addressing is known as register indirect with displacement.
Key Differences Between Direct and Indirect addressing modes
- Direct addressing provides the full address of the main memory in the instruction, where the is stored. On the other hand, in indirect addressing mode, the address is stored at the address field of the instruction.
- The number of memory references required in the direct mode is one, but it is two in the indirect mode for executing the instruction.
- The address space provided in the indirect mode is up to 2N, which is greater than the space provided in the direct addressing mode.
- For executing the instruction using a direct mode, the supplementary calculation is not required. Conversely, the execution of the instruction using indirect addressing mode requires more computations.
- The direct addressing mode is faster than the indirect addressing mode.
The basic difference between the direct and indirect addressing mode is that in the direct mode, the memory location is directly specified. On the contrary, in the indirect addressing mode, the address of the main memory location is specified.