Saturday, August 17, 2013

Computer Organisation and Architecture - Addressing Modes

Addressing Modes– The term addressing modes refers to the way in which the operand of an instruction is specified. The addressing mode specifies a rule for interpreting or modifying the address field of the instruction before the operand is actually executed.
Addressing modes for 8086 instructions are divided into two categories:
1) Addressing modes for data
2) Addressing modes for branch
The 8086 memory addressing modes provide flexible access to memory, allowing you to easily access variables, arrays, records, pointers, and other complex data types.  The key to good assembly language programming is the proper use of memory addressing modes.
An assembly language program instruction consists of two parts



The memory address of an operand consists of two components: 
IMPORTANT TERMS
  • Starting address of memory segment.
  • Effective address or Offset: An offset is determined by adding any combination of three address elements: displacement, base and index.
    • Displacement: It is an 8 bit or 16 bit immediate value given in the instruction.
    • Base: Contents of base register, BX or BP.
    • Index: Content of index register SI or DI.
According to different ways of specifying an operand by 8086 microprocessor, different addressing modes are used by 8086.
Addressing modes used by 8086 microprocessor are discussed below:
Immediate mode: In immediate addressing the operand is specified in the instruction itself. In this mode the data is 8 bits or 16 bits long and data is the part of instruction.

Example: MOV AL, 35H (move the data 35H into AL register)

Register mode: In register addressing the operand is placed in one of 8 bit or 16 bit general purpose registers. The data is in the register that is specified by the instruction.
Example: MOV AX,CX (move the contents of CX register to AX register)
Register Indirect mode: In this addressing the operand’s offset is placed in any one of the registers BX,BP,SI,DI as specified in the instruction. The effective address of the data is in the base register or an index register that is specified by the instruction. 
The 8086 CPUs let you access memory indirectly through a register using the register indirect addressing modes.
Example: MOV AX, [BX] (move contents of memory location addressed by the register BX to the register AX)

Auto-increment mode: 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 consecutive memory location.

Auto-decrement mode: Effective address of the operand is the contents of a register specified in the instruction. Before accessing the operand, the contents of this register are automatically decremented to point to the previous consecutive memory location.

Direct mode: The operand’s offset is given in the instruction as an 8 bit or 16 bit displacement element. In this addressing mode the 16 bit effective address of the data is the part of the instruction.
Example: ADD AL, [0301] (add the contents of offset address 0301 to AL)

Base addressing: The operand’s offset is sum of an 8 bit or 16 bit displacement and the contents of the base register BX or BP. BX is used as a base register for data segment, and BP is used as a base register for stack segment.
Example: MOV AL,[BX+05] (suppose reg. BX contain 0301. The offset will be 0301+05=0306. Content of the memory location 0306 will move to AL)

Indexed addressing mode: The operand’s offset is the sum of the content of an index register SI or DI and an 8 bit or 16 bit displacement.
Example: MOV AX, [SI+05]

Base Indexed addressing mode: The operand’s offset is sum of the content of a base register BX or BP and an index register SI or DI.
Example: ADD AX, [BX+SI]