You are on page 1of 33

EEM3004 Microprocessors

L05
8086 Addressing Modes

Addressing modes provide different ways of computing


the address of an operand. Available addressing modes:
 Register
 Immediate
 Direct
 Register indirect
 Based relative
 Indexed relative
 Based indexed relative
Executing an Instruction

 When the 8086 executes an instruction, it performs


the specified function on data.
 These data are called operands.
- May be a part of the instruction
- May reside in one of the internal registers of the
microprocessor
- May be stored at an address in memory
Register Addressing Mode
Register Addressing Mode

 The operand to be accessed is specified as residing in an


internal register of the 8086
 Memory is not accessed (hence is fast)
 Both operands are in the internal registers
 Source and destination registers must match in size
 Examples:
MOV AX, BX ; Move (MOV) contents of BX (the source
operand) to AX (the destination)
MOV BX, DX
MOV ES, AX
ADD AL, BH
MOV CL, AX (Error)
Register Addressing Mode

CS 01000
0002
________
01002
CS:IP  0100:0002

Pay attention to the value of IP and the contents of AX and BX


Immediate Addressing Mode
Immediate Addressing Mode

 Source operand is part of the instruction.


 Usually immediate operands represent constant data.
 The operands can be either a byte or word. Example:
MOV AL, 15h ; 15h is a byte wide immediate source
operand

No external memory bus cycle is initiated!

 Other examples:
MOV AX, 2550h
MOV CX, 625
MOV BL, 40h
Immediate Addressing Mode
Immediate Addressing Mode
Example for Immediate Addressing
.model small
.stack 0100h
.code
main proc
MOV AL,15h
main endp
end main

Code starts at 06CA:0000 or at CS:IP. Physical address is calculated as 06CA0


+ 0000
06CA0
Direct Addressing Mode
Direct Addressing Mode

 Move a byte or word between a memory location and a


register.
 The locations following the instruction opcode hold an
effective memory address (EA) instead of data.
 The address is a 16-bit offset of the storage location of the
operand from the current value in the data segment
register.
Physical address = DS + offset
 The instruction set does not support a memory-to-
memory transfer!
Direct Addressing Mode
 Data is assumed to be stored in the data segment so DS is
used in calculating the physical address!!!
 External memory bus cycle is needed to do the read
 Example of direct addressing: MOV AL, var1
MOV [offset address],AL
where var1 can be regarded as a variable

 Examples:
MOV DL, [2400h]

or

MOV AL, 99h


MOV [3518h], AL
Direct Addressing Mode
Example for Direct Addressing Mode

.model small
.stack 0100h
.code
main proc
MOV AL, 99h
MOV [DS:3518h],AL
main endp
end main
Example for Direct Addressing Mode
Register Indirect Addressing Mode
Register Indirect Addressing Mode
 Transfer a byte or word between a register and a memory
location addressed by an index or base register.
Example:
MOV AL, [SI]
Here SI is index register and the symbol [ ] always refer to an
address.
 The effective address (EA) is stored either in a pointer
register or an index register.
 The pointer register can be either base register BX or base
pointer register BP.
 The index register can be source index register SI, or
destination index register DI.
 The default segment is DS.
Register Indirect Addressing Mode
 Example: MOV AX, [SI]
Value stored in the SI register is used as the offset address
The segment register is DS in this example. Meaning of the
above is to move the data stored in the memory location DS
+ SI to the AX register
 In register indirect addressing mode, the EA (effective
address) is a variable and depends on the index, or base
register value
 Example: MOV [BX], CL
Which segment register will be used for the above
operation?
 Examples:
MOV CL, [SI]
MOV [DI], AH
MOV [SI], AX
Example for Register Indirect Addressing
Address Content
(in hex) (in hex)  According to the memory map, the
… … result of the operation
01237 XX
01236 XX MOV [BX], CL
01235 XX
can be found as follows:
01234 XX
01233 88 If CL = 88h, BX = 1233h and DS = 0000h
01232 XX then the physical address will be
01231 XX
… … DS shifted left by 1 hex digit (=“0”) + BX =
01233h

Memory map
Example for Register Indirect Addressing

.model small
.stack 0100h
.code
main proc
MOV SI,1234h
MOV AX,[SI]
main endp
end main
Example for Register Indirect Addressing
Register Indirect Addressing Mode
Another Example
Based Relative Addressing Mode
Based Relative Addressing Mode
Example for Based Relative Addressing

.model small
.stack 0100h
.code
main proc
MOV CX,[BX]+10
MOV AL,[BP]+5
main endp
end main
Indexed Relative Addressing Mode
Index Relative Addressing Mode

;PA = DS (sl) + SI + 5

;PA = DS (sl) + DI + 20
Indexed Relative Addressing Mode

DS:SI
02000
2000
1234
05234h
Based Indexed Relative Addressing
Mode
Based Indexed Addressing Mode
Summary of Addressing Modes

You might also like