Addressing Modes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

An instruction contains an operation field, an address field, and a mode field.

The operation field


indicates what operation is to be performed, for example, addition, subtraction, multiplication, etc. The
mode field indicates how the memory address of the operand, which is to be used in an operation, is
determined. To understand the various types of addressing modes, it is important to understand how
the computer deals with instruction. The instruction cycle of a computer goes through the following
three phases:

 Fetch the instruction from the memory


 Decode the instruction
 Execute the instruction

Types of Addressing Modes

 Implicit addressing mode


 Immediate addressing mode
 Direct addressing mode
 Indirect addressing mode
 Register addressing mode
 Register indirect addressing mode
 Auto-increment/decrement addressing mode
 Relative addressing mode
 Indexed addressing mode
 Base register addressing mode

The various types of addressing modes are discussed below:

Implied mode

In this mode, the instruction contains an indirect definition of the operand. An example of an implied
mode instruction is CMA (complement accumulator). Here, the operand (complement) is implicitly
specified in the instruction.

Example: CLC (used to reset Carry flag to 0)

Immediate addressing mode

In this mode, the instruction contains both the opcode and the operand. It can be said that an
instruction that uses the immediate addressing mode contains an operand field in place of an address
field. The operation, as well as the operands, are mentioned in the instruction. An example of
immediate addressing mode instruction is ADD 10. Here, ADD, which is the operation, and 10, which
is the operand, are specified.
Example: MOV AL, 35H (move the data 35H into AL register)

Register mode

In this mode, the instruction specifies a register. This register stores the operand. An example of
register mode instruction is:

AC = AC + [R]

Example: MOV AX,CX (move the contents of CX register to AX register)

This will add the operand stored at register R to the operand stored in the accumulator.

Register indirect mode

In this mode, the instruction specifies a register. This register stores the effective address of the
operand. An instruction that uses register indirect addressing mode is:

AC = AC + [[R]]

MOV AX, [BX](move the contents of memory location s


addressed by the register BX to the register AX)

Here, the contents which reside in the memory location specified by the register R will be added to
the contents of the accumulator.

Direct addressing mode

In this mode, the instruction specifies an address. This address is the address of the operand. An
example of a direct addressing mode instruction is:

AC = AC + [X]

Example: ADD AL,[0301] //add the contents of offset address 0301 to AL

This will add the operand stored at address X with the operand stored in the accumulator. This mode
is also referred to as absolute addressing mode.

Indirect addressing mode

In this mode, the instruction specifies an address. The memory location specified by the address
contains the address of the operand. An example of an indirect addressing mode instruction is:

AC = AC + [[X]]
This will add the operand stored at the address specified by the memory location X with the contents
of the accumulator.

Auto-increment/decrement mode

In this mode, the instruction specifies a register which points to a memory address that contains the
operand. However, after the address stored in the register is accessed, the address is incremented or
decremented, as specified. The next operand is found by the new value stored in the register.

Example: Increment
Add R1, (R2)+ // OR
R1 = R1 +M[R2]
R2 = R2 + d

Example : Decrement
Add R1,-(R2) //OR
R2 = R2-d
R1 = R1 + M[R2]

Relative address mode

In this mode, the contents of the address field are added to the constant stored in the program
counter. The result of the addition gives the address of the operand. For example, suppose the
address field contains 850, and the program counter contains 20, then the operand will be at memory
location 850 + 20 = 870.

Indexed addressing mode

In this mode, the address of the operand is determined by adding the contents of the address field
and the contents of the index register.

Example: MOV AX, [SI +05]

Base register addressing mode

In this mode, the address of the operand is determined by adding the contents of the address field
and the contents of the base register.

Applications of Various Addressing Modes


The applications of various addressing modes are as follows:

 Immediate addressing mode: Used to set an initial value for a register. The value is usually a
constant
 Register addressing mode/direct addressing mode: Used to implement variables and access
static data
 Register indirect addressing mode/indirect addressing mode: Used to pass an array as a
parameter and to implement pointers
 Relative addressing mode: Used to relocate programs at run time and to change the execution
order of instruction
 Index addressing mode: Used to implement arrays
 Base register addressing mode: Used to write codes that are relocatable and for handling recursion
 Auto-increment/decrement addressing mode: Used to implement loops and stacks

Purpose of Addressing Mode

The addressing modes serve the following purposes:

 To decrease the number of bits contained in an instruction’s address field


 To provide users with programming versatility by providing facilities such as counters, pointers,
indexing, and program relocation

Conclusion

The addressing mode is one of the fields in an instruction. This field determines how and where an
operand is fetched from the memory. The various types of addressing modes are:

You might also like