1.5 EEEQ 472 - 8086 Microproessor - Addressing Modes

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

9/30/2021

Introduction
 When 8086 executes an instruction, it performs the specified

function on data
8086 Microprocessor Architecture  These data are called its operands and may be:
(Addressing Modes)  part of the instruction

 reside in one of the internal registers of the microprocessor

 stored at an address in memory

 held at an I/O port

 to access these different types of operands, the 8086 is

provided with various addressing modes (Data Addressing


Modes)

2 8086 Addressing Modes 9/30/2021

Data Addressing Modes of 8086 Data Addressing Modes of 8086…


 8086 microprocessor has 12 addressing modes. These  Addressing modes for accessing immediate and register data:

addressing modes can be classified into five groups:  Immediate Addressing Mode

 Addressing modes for accessing immediate and register  Register Addressing Mode
data (register and immediate addressing modes (2))  Memory Addressing Modes:
 Addressing modes for accessing data in memory (memory
 Direct Addressing Mode
addressing modes (6))
 Register Indirect Addressing Mode
 Addressing modes for accessing I/O ports (I/O or Port
 Based Addressing Mode
addressing modes (2))
 Indexed Addressing Mode
 Relative addressing mode (1)
 Based Indexed Addressing Mode
 Implied addressing mode (1)
 String Addressing Mode

3 8086 Addressing Modes 9/30/2021 4 8086 Addressing Modes 9/30/2021

1
9/30/2021

Data Addressing Modes of 8086… Immediate addressing mode


 I/O or Port Addressing Modes:  8 or 16 bit data can be specified as part of the instruction

 Direct Port Addressing Mode OP Code | Immediate Operand


 Indirect Port Addressing Mode  Examples:

 Relative Addressing Mode  MOV CL, 03 H; Moves the 8 bit data 03H into CL
 Implied Addressing Mode  MOV DX, 0525 H; Moves the 16 bit data 0525H into DX

 In the above two examples, the source operand is in


immediate mode and the destination operand is in register
mode

5 8086 Addressing Modes 9/30/2021 6 8086 Addressing Modes 9/30/2021

Immediate addressing mode… Register addressing mode


 A constant such as “VALUE” can be defined by the assembler  The operand to be accessed is specified as residing in an

EQUATE directive such as: internal register of 8086

VALUE EQU 35H  Examples:

 MOV BH, VALUE; loads 35H into BH  MOV DX, CX; moves 16 bit content of CS into DX
 MOV CL, DL; moves 8 bit contents of DL into CL
 MOV BX, CH; an illegal instruction

register sizes must be the same

7 8086 Addressing Modes 9/30/2021 8 8086 Addressing Modes 9/30/2021

2
9/30/2021

Direct addressing mode Direct addressing mode…


 The instruction opcode is followed by an Effective Address(EA)  By using a segment override prefix (SOP) in the instruction,

 EA is directly used as the 16 bit offset of the storage location of any of the four segment registers can be referenced

the operand from the location specified by the current value in


the selected segment register

 The default segment is always DS

 The 20 bit physical address of the operand in memory is

normally obtained as:

PA = DS : EA

9 8086 Addressing Modes 9/30/2021 10 8086 Addressing Modes 9/30/2021

Direct addressing mode… Direct addressing mode…


 The Execution Unit (EU) has direct access to all registers and  Examples:

data for register and immediate operands. However the EU  MOV CX, START
cannot directly access the memory operands.  If the 16 bit value assigned to the offset START by the
 EU must use the BIU in order to access memory operands programmer using an assembler pseudo instruction such
 In the direct addressing mode, the 16 bit effective address as DW is 0040 and [DS] = 3050
(EA) is taken directly from the displacement field of the  Then BIU generates the 20 bit physical address 30540H.

instruction  The content of 30540 is moved to CL

 The content of 30541 is moved to CH

11 8086 Addressing Modes 9/30/2021 12 8086 Addressing Modes 9/30/2021

3
9/30/2021

Direct addressing mode… Register indirect addressing mode


 Examples:  EA is specified in either pointer (BX) register or an index (SI or
DI) register
 MOV CH, START
 The 20 bit physical address is computed using DS and EA
 If [DS] = 3050 and START = 0040

 8 bit content of memory location 30540 is moved to CH 𝐶𝑆


𝐵𝑋
𝐷𝑆
 MOV START, BX 𝑃𝐴 = + 𝑆𝐼
𝑆𝑆
𝐷𝐼
 With [DS] = 3050, the value of START is 0040 𝐸𝑆
 Example:
 Physical address : 30540
 MOV [DI], BX
 MOV instruction moves (BL) and (BH) to locations 30540
 If [DS] = 5004, [DI] = 0020, [BX] = 2456 then PA=50060
and 30541 respectively  The content of BX(2456) is moved to memory locations
50060H and 50061H

13 8086 Addressing Modes 9/30/2021 14 8086 Addressing Modes 9/30/2021

Based addressing mode Based addressing mode…


 Example:

𝐶𝑆  MOV AL, START [BX]


𝐵𝑋
𝐷𝑆
𝑃𝐴 = ∶ 𝑜𝑟 + 𝐷𝑖𝑠𝑝𝑙𝑎𝑐𝑒𝑚𝑒𝑛𝑡
𝑆𝑆 or
𝐵𝑃
𝐸𝑆
 MOV AL, [START + BX]

 EA : [START] + [BX] for both cases

 when memory is accessed PA is computed from BX and DS  PA : [DS] + [EA]

 The 8 bit content of PA is moved to AL


 when the stack is accessed PA is computed from BP and SS

15 8086 Addressing Modes 9/30/2021 16 8086 Addressing Modes 9/30/2021

4
9/30/2021

Based addressing mode… Based addressing mode…


 The based addressing mode with BP is a very convenient way  This instruction sequence can be depicted as follows:

to access stack data

 BP can be used as a stack pointer in SS to access local

variables. Consider the following instruction sequence


(arbitrarily chosen to illustrate the use of BP for stack):

17 8086 Addressing Modes 9/30/2021 18 8086 Addressing Modes 9/30/2021

Indexed addressing mode Based Indexed addressing mode

𝐶𝑆 𝐶𝑆
𝑆𝐼 𝐵𝑋 𝑆𝐼
𝐷𝑆 𝐷𝑆
𝑃𝐴 = ∶ 𝑜𝑟 + 8 𝑜𝑟 16 𝑏𝑖𝑡 𝑑𝑖𝑠𝑝𝑙𝑎𝑐𝑒𝑚𝑒𝑛𝑡  𝑃𝐴 = ∶ 𝑜𝑟 + 𝑜𝑟 + 8 𝑜𝑟 16 − 𝑏𝑖𝑡 𝑑𝑖𝑠𝑝𝑙𝑎𝑐𝑒𝑚𝑒𝑛𝑡
𝑆𝑆 𝑆𝑆
𝐷𝐼 𝐵𝑃 𝐷𝐼
𝐸𝑆 𝐸𝑆
 Example:

 MOV BH, START [SI]  Example:

 The content of this memory is moved into BH  MOV ALPHA [SI] [BX], CL

 If [BX] = 0200, ALPHA = 08, [SI] = 1000 and [DS] =

3000 then PA = 31208


 8 bit content of CL is moved to 31208 memory address

19 8086 Addressing Modes 9/30/2021 20 8086 Addressing Modes 9/30/2021

5
9/30/2021

String addressing mode String addressing mode…


 The string instructions automatically assume that SI points to  Source address : 20500, assume it contains 38

the first byte or word of the source operand and DI points to  PA : [DS] + [SI]
the first byte or word of the destination operand  Destination address : [ES] + [DI] = 40300, assume it
 The contents of SI and DI are automatically incremented (by contains 45
clearing DF to 0 by CLD instruction) to point to the next byte or  After executing MOV S BYTE:
word
 [40300] = 38
 Example:  [SI] = 0501
 MOV S BYTE  [DI] = 0301
 If [DF] = 0, [DS] = 2000, [SI] = 0500

 [ES] = 4000, [DI] = 0300

21 8086 Addressing Modes 9/30/2021 22 8086 Addressing Modes 9/30/2021

I/O mode (direct) I/O mode (indirect)


 Port number is an 8 bit immediate operand  The port number is taken from DX

 Example:  Examples:

 OUT 05H, AL  IN AL, DX

 Outputs [AL] to 8 bit port 05H  If [DX] = 5040

 8 bit content of port 5040 is moved into AL

 IN AX, DX

 If [DX] = 5040

 8 bit contents of ports 5040 and 5041 are moved into AL

and AH respectively

23 8086 Addressing Modes 9/30/2021 24 8086 Addressing Modes 9/30/2021

6
9/30/2021

Relative addressing mode Relative addressing mode…


 Instructions using this mode specify the operand as a signed 8-  An advantage of relative mode is that the destination address

bit displacement relative to IP is specified relative to the address of the instruction after the

 Example: conditional Jump instruction

 JNC START  Since the 8086 conditional Jump instructions do not contain an

 If CY=0, then PC is loaded with current PC contents plus 8 absolute address, the program can be placed anywhere in

bit signed value of START, otherwise the next instruction is memory which can still be executed properly by the 8086

executed  A program which can be placed anywhere in memory, and can

still run correctly is called a “relocatable” program

 It is a good practice to write relocatable programs

25 8086 Addressing Modes 9/30/2021 26 8086 Addressing Modes 9/30/2021

Implied addressing mode Summary of 8086 Addressing Modes


 Instruction using this mode have no operands

 Example:

 CLC: Clear Carry Flag

 CMC – Complement Carry Flag

 STC – Set Carry Flag

 CLD – Clear Direction Flag

 STD – Set Direction Flag

 CLI – Clear Interrupt Flag

 STI – Set Interrupt Flag

27 8086 Addressing Modes 9/30/2021 28 8086 Addressing Modes 9/30/2021

7
9/30/2021

Special functions of general-purpose registers Special functions of general-purpose registers…


 AX & DX registers:  BX register:

 In 8 bit multiplication, one of the operands must be in AL.  In instructions where we need to specify in a general purpose
The other operand can be a byte in memory location or in register the 16 bit effective address of a memory location, the
another 8 bit register
register BX is used (register indirect)
 The resulting 16 bit product is stored in AX, with AH storing
the MS byte
 In 16 bit multiplication, one of the operands must be in AX.
The other operand can be a word in memory location or in
another 16 bit register
 The resulting 32 bit product is stored in DX and AX, with DX
storing the MS word and AX storing the LS word

29 8086 Addressing Modes 9/30/2021 30 8086 Addressing Modes 9/30/2021

Special functions of general-purpose registers… Assignment II


 CX register:
Exercise 1
 In loop instructions, CX register will be always used as the
 Determine the addressing modes for the following 8086
implied counter
 In I/O instructions, the 8086 receives into or sends out data instructions:

from AX or AL depending as a word or byte operation. In


a) CLC
these instructions the port address, if greater than FFH has
to be given as the contents of DX register b) CALL WORDPTR [BX]

 Example: c) MOV AX, DX


 IN AL, DX
d) ADD [SI], BX
 DX register will have 16 bit address of the I/P device

31 8086 Addressing Modes 9/30/2021 32 8086 Addressing Modes 9/30/2021

8
9/30/2021

Assignment II… Assignment II…


Exercise 2 Exercise 3

 Describe the addressing modes for each of the following 8086  The contents of the following registers are: CS = 0187H, DS =

example instructions and briefly explain what the instruction 4289H, SS = 22A8H, IP = 13DAH, SP = 1179H, and DI =
achieves. 0A96H

a) MOV ALPHA [SI] [BX], CL a) Determine the addresses of the next two instructions to be

b) MOV BH, START [SI] computed.

c) MOV AX, 1234H b) Determine the size and range of addresses for the stack
segment.
d) MOV AX, [2500H]

e) MOV AX,[BX]

33 8086 Addressing Modes 9/30/2021 34 8086 Addressing Modes 9/30/2021

Assignment II… Assignment II…


 Exercise 4  Exercise 5

 Given that [DS] = 3050 and the value of START is 0040,  Determine the physical address for each of the instructions

compute the physical address and explain what the instruction below given that [BX] = 0209, [CX] = 0408, ALPHA = 09, [SI]
MOV START, BX achieves. = 1000, [DS] = 3000, [SS] = 4000, [ES] = 2000, [DI] =
0020, START = 0070, [IP] = 0146, [BP] = 0016, and [SP] =
0040.

a) MOV ALPHA [SI] [BX], CL

b) MOV START[BP], BX

c) MOV BH, START [SI]

35 8086 Addressing Modes 9/30/2021 36 8086 Addressing Modes 9/30/2021

9
9/30/2021

END

37 8086 Addressing Modes 9/30/2021

10

You might also like