Here is the description of Addressing Modes:
Addressing modes in computer architecture define how processors specify the operands for the instructions they execute.
- An addressing mode specifies a rule for interpreting or generating an effective address (EA) or data operand.
- The effective address is the location of the operand in memory or in a register. Different addressing modes provide flexibility and efficiency in programming.
Note:
Computer use addressing mode techniques for the purpose for accommodating one or both of the following provisions:
- To give programming versatility to the user by providing such facilities as pointers to memory, counters for loop control, indexing of data and program relocation.
- To reduce the number of bits in the addressing field of the instruction.
Mode Field:
- The mode field is used to locate the operands needed for the operation.
- The mode field helps the processor interpret how to fetch the operand for the given instruction.
Program counter:
• The program counter (PC) is a register in a computer processor that indicates the address of the next instruction to be executed.
• It is a fundamental component of the fetch-decode-execute cycle, which is the basic operation cycle of a computer’s central processing unit (CPU).
Here are some common Addressing Modes:
1.) Implied Addressing Mode:
In this mode the operands are specified implicitly in the definition of the instruction.
- For example: the ‘complement accumulator’ instruction is an implied mode instruction because the operand in the accumulator register is implied in the definition of the instruction itself.
- All register reference instructions that use an accumulator are implied mode instructions.
- Zero address instructions in a stack organized computer are implied mode instructions since the operands are implied to be on the top of the stack.
- Example : CMA
2.) Immediate addressing Mode:
In this mode the operand is specified in the instruction itself.
- In other words, an immediate mode instruction has a operand field rather than an address field.
- The operand field contains the actual operand to be used in conjunction with the operation specified in the instruction.
- Immediate mode instructions are useful for initializing registers to a constant value.
- Example: ADD 5
- Add 5 to contents accumulator of
- 5 is operand
3.)Direct Addressing Mode:
In this mode the effective address is equal to the address part of the instruction.
- The operand resides in memory and its address is given directly by the address field of instruction.
- In a branch type instruction the address field specifies the actual branch address:
- Effective address (EA) = address field (A)
- Example:
- LDA A
- Look in memory at address A for operand.
- Load contents of A to accumulator
4.) Indirect Addressing Mode:
In this mode the address field of the instruction gives the address where the effective address is stored in memory/register.
- Control fetches the instruction from memory and uses its address part to access memory again to read the effective address.
- EA = address contained in register/memory location
- Example Add (M)
- Look in M, find address contained in M and look there for operand
- Add contents of memory location pointed to by contents of M to accumulator
5.) Register Addressing Mode:
In this mode the operands are in the registers that reside within the CPU.
- EA = R
- Example : ADD R1,R2
6.) Register indirect addressing mode:
In this mode the instruction specifies a register in the CPU whose contents give the effective address of the operand in the memory.
- In other words, the selected register contains the address of the operand rather than the operand itself.
- Before using a register indirect mode instruction, the programmer must ensure that the memory address of the operand is placed in the processor register with a previous instruction. The advantage of a register indirect mode instruction is that the address field of the instruction uses fewer bits to select a register than would have been required to specify a memory address directly.
- Therefore EA = the address stored in the register R
- Operand is in memory cell pointed to by contents of register
- Example Add (R2),R0
7.)Autoincrement or autodecrement addressing mode:
‣ Autoincrement Mode:
The effective address of the operand is the contents of a register specified in the instruction. After accessing the operand, the contents of this register are automatically incremented to point to the next item in a list.
• We denote the Autoincrement mode by putting the specified register in parentheses, to show that the contents of the register are used as the effective address, followed by a plus sign to indicate that these contents are to be incremented after the operand is accessed. Thus, the Autoincrement mode is written as (Ri) +
‣ Autodecrement mode:
The contents of a register specified in the instruction is first automatically decremented and is then used as the effective address of the operand.
We denote the Autodecrement mode by putting the specified register in parentheses, preceded by a
minus sign to indicate that the contents of the register are to be decremented before being used as the effective address. Thus, we write – (Ri)
• These two modes are useful when we want to access a table of data.
ADD (R1)+
will increment the register R1.
LDA -(R1)
will decrement the register R1.
8.)Relative addressing mode:
In this mode the content of the program counter is added to the address part of the instruction in order to obtain the effective address.
• Effective address is defined as the memory address obtained from the computation dictated by the given addressing mode. The address part of the instruction is usually a signed number (in 2’s complement representation) which can be either positive or negative. When this number is added to the content of the program counter, the result produces an effective address whose position in memory is relative to the address of the next instruction.
- Relative addressing is often used with branch type instructions when the branch address is in the area surrounding the instruction word itself. It results in a shorter address field in the instruction format since the relative address can be specified with a smaller number of bits compared to the bits required to designate the entire memory address.
- EA = A + contents of PC
- Example: PC contains 825 and address pa rt of instruction contains 24.
- After the instruction is read from location 825, the PC is incremented to 826. So EA=826+24=850. The operand will be found at location 850 i.e. 24 memory locations forward from the address of the next instruction.
9.) Indexed addressing mode:I
In this mode the content of an index register is added to the address part of the instruction to obtain the effective address. The index register is a special CPU register that contains an index value.
• The address field of the instruction defines the beginning address of a data array in memory. Each operand in the array is store din memory relative to the beginning address. The distance between the beginning address and the address of the operand is the index value stored in the index register.
• Any operand in the array can be accessed with the same instruction provided that the index register contains the correct index value. The index register can be incremented to facilitate access to consecutive operands. Note that if an index type instruction does not include an address field in its format, then the instruction converts to the register indirect mode of operation.
- Therefore EA = A + IR
- Example MOV AL , DS: disp [SI] Advantage
- Good for accessing arrays.
10.) Base Register addressing Mode:
In this mode the content of base register is added to the address part of the instruction to obtain the effective address.
• This is similar to the indexed addressing mode except that the register is now called a base register instead of an index register. The difference between the two modes is in the way they are used rather than in the way that they are computed.
- An index register is assumed to hold an index number that is relative to the address part of the instruction. A base register is assumed to hold a base address and the address field of the instruction gives a displacement relative to this base address. The base register addressing mode is used in computers to facilitate the relocation of the programs in memory. When programs and data are moved from one segment of memory to another, as required in multiprogramming systems, the address values of instructions must reflect this change of position. With a base
- register, the displacement values of instructions do not have to change. Only the value of the base register requires updating to reflect the beginning of a new memory segment.
- Therefore EA= A + BR
- For example: MOV AL, disp [BX]
Numerical Example:
Here is the numerical example for addressing modes: