Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
In computer architecture, addressing modes play a pivotal role in defining how processors access memory and operands to perform various operations. Understanding addressing modes is essential for computer scientists, engineers, and enthusiasts alike, as they provide insights into the inner workings of CPUs and their interaction with memory.
This blog will discuss different types of addressing modes in computer architecture.
The Addressing mode refers to how the operand of an instruction is specified. It specifies a rule for interpreting/modifying the address field of the instruction before referencing the operand.
Before jumping to different addressing modes, it is crucial that we first understand the basic concept of the operation cycle of a computer. The control unit is designed to go through an instruction cycle divided into three major phases:
Fetch the instruction from memory: Program Counter (PC) is one of the registers present in the system that keeps track of the program’s instructions stored in the memory. It holds the address of the next instruction to be executed and is incremented every time an instruction is fetched from memory.
Decode the instruction: It determines the operation to be performed: the operands' location and the instruction's addressing mode. Further, the computer executes the instruction and returns to step 1 (fetching the instruction from memory) to fetch the next instruction in the sequence.
Execute the instruction: The addressing mode of the instruction is specified with a unique binary code that designates both the operation and the mode of the instruction. Instructions can be defined with a variety of addressing modes. Combining two or more addressing modes in one instruction is also possible.
The operands needed for the operation are located using the mode field. It is not necessary to have an address field in the instruction. An address field can contain either a memory address or a processor register if there is an address field.
Addressing mode refers to the way in which the operand of an instruction is specified or accessed in a computer’s memory.
It defines how the effective address of the operand is calculated and where it is located.
Different types of addressing modes exist, such as Immediate, Direct, Indirect, Register, and Indexed addressing.
Addressing modes provide flexibility in data access, allowing for more efficient memory usage and instruction execution.
Importance of Addressing Modes
Flexibility: Allows programmers to choose the most efficient way to access data based on program requirements.
Efficiency: Optimizes memory usage and execution speed by providing different methods of accessing operands.
Complexity Reduction: Simplifies instruction formats and enables more concise, powerful code.
Enhanced Performance: Improves CPU performance by reducing the number of memory accesses required for certain operations.
Types of Addressing Modes
Addressing Modes in computer architecture are further divided into the following parts:
Implied/ Implicit Addressing Mode
Immediate Addressing Mode
Register Direct Addressing Mode
Register Indirect Addressing Mode
Auto-Increment Addressing Mode
Auto-Decrement Addressing Mode
Direct Addressing Mode
Indirect Addressing Mode
Displacement Addressing Mode
Relative Addressing Mode
Indexed Addressing Mode
Base Register Addressing Mode
Stack Addressing Mode
Implied/ Implicit Addressing Mode
The operands are implicitly specified in the instruction’s definition. Consider the example, the instruction “complement accumulator” is an implied-mode instruction as the operand in the accumulator register is implied in the instruction definition. All register reference the instructions that use an accumulator are implied-mode instructions. Zero-address instructions in a stack-organized computer are also implied-mode instructions because the operands are implied to be on top of the stack.
Immediate Addressing Mode
The operand is defined in the instruction itself. This mode instruction has an operand field instead of an address field. The operand field contains the actual operand used with the specified operation in the instruction. The immediate-mode instructions help initialize registers to a constant value.
For example, ADD 8 will increment the value stored in the accumulator by 8.
Register Direct Addressing Mode
The operands that reside within the CPU are stored in the registers. The specific register is selected from a register field in the instruction. No reference to the memory is required to fetch the operand. The only difference between the Direct addressing mode and the register direct addressing mode is that the instruction address field refers to a CPU register instead of the main memory.
Advantage: This mode provides faster memory access to the operands. Disadvantage: It has limited address space, and using multiple registers can help boost the performance, but it complicates the instructions.
Register Indirect Addressing Mode
The instruction defines a register in the CPU that stores the effective address of the operand in memory. Only one reference to the memory is required to fetch the operand. The specified register contains the address of the operand instead of the operand. The only difference between the Indirect addressing mode and the register indirect addressing mode is that the instruction address field refers to a CPU register.
For example: ADD R1, R2: Here, the content of R2 is added to R1. R1 R2 represents registers. Advantage: The instruction address field uses fewer bits to select a register than required to specify a memory address directly.
Auto-Increment Addressing Mode
This mode is a special Register Indirect Addressing Mode case. The register is incremented/decremented after or before its value is utilized. EA = content of the register.
The content of the register is increment automatically by step size ‘d’ after accessing the operand, where the step size ‘d’ depends on the size of the accessed operand. Only one reference memory is required to fetch the operand.
Consider an example:
Here, the Effective Address (R) =178, and the operand in AC are 7. After loading R1 is incremented by 1 and becomes 179.
Auto-Decrement Addressing Mode
This mode is also a special Register Indirect Addressing Mode case. EA = content of the register - step size.
The content of the register is decremented by step size ‘d’ after accessing the operand, where the step size ‘d’ depends on the size of the accessed operand. Only one reference memory is required to fetch the operand.
Consider an example:
Here, register R1 is decremented by 1 (400-1=399) prior to the instruction execution which implies that the operand loaded to the AC is of address 1099H instead of 1088H. Hence, the Effective Address is 1099H.
Direct Addressing Mode
The effective address of the operand resides in the address field of the instruction. The operand resides in the memory, and the address field of the instruction gives its address. Only one reference to the memory is required to fetch the operand, and no additional calculations need to be done to find the effective address of the operand. It is also known as absolute addressing mode.
For example, ADD X will increment the value stored in the accumulator by the value stored at X's memory.
Indirect Addressing Mode
The address field of the instruction gives the address of the memory location that contains the effective address of the operand. Two references to the memory are required to fetch the operand: The control fetches the instruction from memory and uses its address part to reaccess the memory that stores the effective address. This addressing mode slows down the execution as it requires multiple memory lookups to find the operand.
Displacement Addressing Mode
The indexed register content is added to the instruction’s address part to obtain the effective address of the operand.
EA = A + (R) Here, the address field holds two values, A: Base value R: displacement value.
Relative Addressing Mode
This mode is another version of the displacement address mode. The program counter’s content is added to the instruction’s address part to obtain the effective address.
EA = A + (PC) Here, EA: Effective address, PC: program counter.
The instruction’s address part is usually a signed number that can be positive or negative. After the instruction’s address is fetched, the value of the program counter increases immediately, irrespective of whether the fetched instruction has been executed or not. PC: It contains the address of the next instruction to be executed.
Consider an example:
The program counter contains the number 422, and the address part of the instruction contains the number 17. The instruction at location 421 is read during the fetch phase, and the program counter is then incremented by one to 422 + 17 = 439.
Indexed Addressing Mode
The index register’s content is added to the instruction’s address to obtain the effective address. EA = content of index register + Instruction address part
Base Register Addressing Mode
This mode is another version of the displacement address mode. To obtain the effective address, the base register’s content is added to the instruction’s address. EA = A + (R) A: Displacement, R: Pointer to the base address.
Stack Addressing Mode
The operand resides at the top of the stack. Consider an example, ADD: This instruction will POP two items from the stack, add them, and at last, will PUSH the result to memory references of Addressing Modes. It helps in reducing the number of bits in the instruction's addressing field. It facilitates pointers, indexing of data, and counters for loop controls.
Applications of Addressing Modes
The applications of Addressing Modes are:-
Immediate Addressing Mode: It initialize the register to a constant value.
Direct Addressing Modes and Register Direct Addressing Mode: It helps access static data and implement variables.
Indirect Addressing Modes and Register Indirect Addressing Mode: It helps implement pointers and pass arrays as parameters.
Relative Addressing Mode: It helps in program relocation at runtime. And in changing the sequence of instructions during execution.
Base Register Addressing Mode: It helps in writing relocatable code and handling recursive procedures.
Index Addressing Mode: It helps in the array and record implementation.
Auto-Increment Addressing Mode and Auto-Decrement Addressing Mode: It helps implements loops and stacks.
Advantages of Addressing Modes
They improve performance by efficiently utilizing the CPU cache and reducing the memory read latency
Addressing Modes are used for implementing complex data structures in memory as they provide mechanisms such as indexing
Program sizes can be reduced drastically as the code can be compacted which allows faster execution of instructions
Addressing modes give you the flexibility to use different ways of specifying the address of operands in your instructions
Disadvantages of Addressing Modes
Complexity: Particularly for inexperienced programmers, some addressing modes might be challenging to comprehend and use. Due to its intricacy, code may include errors or be inefficient
Limited Flexibility: Some addressing modes may limit the kind of operand operations that can be carried out. For instance, Immediate Mode restricts dynamic calculations to preset values only
Increased Memory Access: Because Direct and Indirect modes need more memory accesses to retrieve operands, program performance may be slowed down
Register Dependency: The availability of registers is very important for register modes. This can cause conflicts and inefficient resource utilization in systems with a finite number of registers
Code Size: Certain addressing modes could provide longer and more complicated instructions, increasing the code size
Frequently Asked Questions
What is the implied addressing mode?
In the implied addressing mode, the operand is implicitly specified by the instruction itself, without explicitly referencing a memory location or register. This mode is commonly used for instructions that operate on the accumulator or have predefined operands.
Why addressing mode is used?
The Addressing mode refers to how the operand of an instruction is specified. We can specify how an operand's effective address is represented in any particular instruction by using the addressing modes. There is only one memory reference needed and no additional computation.
What are the 5 addressing modes?
The addressing mode include Register Mode, which places the operand in a register, Immediate Mode, which places a constant value in the instruction, Direct Mode, which places the operand address in the instruction, Indirect Mode, which places the address in a register, and Indexed Mode, which determines the address using the base register and offset.
What are addressing modes and its types?
Computer architecture's addressing modes control how a processor accesses information in memory while carrying out an instruction. The five main types are Indexed Mode, Register Mode, Immediate Mode, Direct Mode, and Indirect Mode.
Conclusion
In this article, we have extensively discussed Addressing Modes in Computer Architecture. The addressing mode specifies a rule for modifying the address field of the instruction before referencing the operand. We hope that this blog has helped you enhance your knowledge regarding addressing modes in computer architecture.