0% found this document useful (0 votes)
83 views

Chapter 4 Addressing Mode

This document discusses various addressing modes of 8086 processor. It describes data, program and stack addressing modes. It further explains different data addressing modes like register, immediate, direct, register indirect, register relative and base plus index addressing modes.

Uploaded by

eliasferhan1992
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Chapter 4 Addressing Mode

This document discusses various addressing modes of 8086 processor. It describes data, program and stack addressing modes. It further explains different data addressing modes like register, immediate, direct, register indirect, register relative and base plus index addressing modes.

Uploaded by

eliasferhan1992
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

8086 Addressing Modes

Addressing Modes
• When 8086 execute on instruction , it performs the specified function on data.
• The various formats of specifying the operand are called addressing
mode.
• Addressing modes provide different ways for accessing an address to
given data to a processor.
Addressing modes can be broadly classified as
1. Data addressing modes
2. Program memory addressing modes
3. Stack memory addressing modes
1. Data addressing modes
The mode is related to data transfer operation ,that is data
transferred from the memory to internal register of 8086 processor or
from one register to another register.
Data addressing modes can be classified as:
1. Addressing modes for accessing immediate and register data
2. Addressing modes for accessing data in memory
3. Addressing modes for accessing I/O ports
Addressing modes for accessing immediate and register
data
– There are two ways:

1. Register addressing modes and


2. Immediate addressing modes
1. Register addressing modes:
– Here the source operand, destination operand are contained
in an
8086 register. Never mix an 8-bit register with 16-bit.
-CS Register is not a desti nati on.
MOV
The AL, BL is: ; copies the contents of BL to
instruction
AL.
Direction of data flow
AL BL
Addressing Modes
2. Immediate Addressing Modes
– Here, A constant data is copied to a register. The instruction
is:
MOV AL, 20H ; copies the 20H to AL register (8 bit
data).
MOV AX, 1234H ; copies the 1234H to AX register (16 bit
data).
Examples
1. Load the immediate number 67 into register AL and
copy the content of AL into DH register.
– Answer : MOV AL, 43H; ; b/c
(67)10=43H MOV DH, AL;
2. Change the following HL language to 8086 AL (use
only 8086 register)? int z=10019; => MOV AX, 2723H;
HLL AL
int y=14861; MOV AX, 3A0DH;
int MOV DX, 1770H;
x=6000; MOV CX, 3A0DH;
int temp=y; MOV AX, DX;
Y=x; MOV DX, CX
X=temp;
Addressing modes For Accessing Memory
The Execution Unit has direct access to all registers and data for
register and immediate operands. However, the EU can't directly
access memory operands.
When the execution unit needs to access a memory location, it
sends an offset value to the BIU. This offset is also called the
Effective Address.
Effective Address (EA) is the displacement of the desired location
from the segment base.
There are six ways to specify effective address in the instruction:
1)Direct 4) Register relative
2) Register indirect 5) Base Relative Plus index
3) Base Plus Index 6) String addressing
modes
 The 80386 and above also include scaled-index.
1. Direct data addressing mode
 It moves a byte or word between a data segment memory
location and register.
 The effective address is given directly in the source.
 Example : MOV AL,DS:[1234H] –A memory location 1234h
store in data segment copy to AL.
Example: MOV CL, [9823H]
This instruction will copy the contents of the memory location
at offset of 9823H from the data segment base into the CL
register. Here; 9823H is the effective address which is written
directly in the instruction.
Addressing modes For Accessing Memory
Direct addressing mode
example:
Examples
1. Save the number 7876 in the physical memory location
4A37BH using direct addressing mode.Compute the offset
address if the segment number is 4OFFH.
Answer: look from the simulator that DS=40FFH;
MOV DX, 1EC4H;
MOV [938BH], DX;

2. Load the above memory location (i.e. physical address


4A37BH) into AX register.
Solution: MOV DX, 1EC4H;
MOV [938BH], DX;
MOV AX, [938BH];
2. .Register Indirect addressing mode
 Register addressing transfers a byte or word between a register
and memory location addressed by an index or base register.
 The index and base register are BP,BX,DI & SI . These registers
hold the offset address of the memory location.
 The data segment used by default with register indirect
addressing, or any other addressing mode that use BX,DI or SI to
address memory.
 If BP register address memory , the stack segment is used by
default.
 Example: MOV CX,[BX] -Copies the content of data segment
memory location addressed by BX into CX.
 PA=DS*10+BX
 MOV [BX].CL
Example
MOV [DI], BX
This instruction copies the 16 bit contents of BX into a memory
location offset by the value of EA specified in DI from the current
content in DS.
Now, if[DS]=7205H, [DI]=0030H, and [BX]=8765H then after
MOV [DI], BX content of BX (8765H) is copied to memory
locations 72080H and 72081H.
Cont.
MOV DL, [BP]
– This instruction copies the 8-bit content from the memory location
offset by the value of EA specified in BP from the content of SS. B/C
data addressed by BP are default located in Stack Segment (SS).
– Look the ff. for indirect addressing mode
– EXAMPLE: MOV CX,2000H MOV SI,CX MOV BX,[SI]
Examples
Save the number 7876 in the physical memory location
7100 using Register indirect addressing mode.
Answer: look from the simulator that DS=700;
- the offset is 7100-7000=100
- offset should be stored on the DI register.
MOV DI, 100H;
MOV DX, 1EC4H;
MOV [DI], DX;
3. Register relative addressing/ base addressing mode
It moves a byte or word between a register and the
memory location addressed by an index or base
register (BP,BX,DI or SI) plus a displacement.
Example
- MOV AX,[DI+100H]; Copies the word content of
the data segment memory location address by DI
plus 100h into AX.
- DS*10+DI+100H
– Note: displacement can be subtracted from the register:
 MOV AL, [DI-2]
Cont.
– MOV CX, [BX+0003H]
Addressing modes For Accessing Memory
Register relative addressing modes
– Displacement can be an offset address appended to
the front of the [] :
MOV AL, OFF_ADD[DI+4]
E.g. MOV AL, LAST[SI+2]
This instruction copies
the contents of the 20 bit
address computed from the displacement SI+2 index
into AL.
3 Register relative addressing modes
– The figure below shows how to address data elements within
the
array with register relative addressing mode.
- Copies the consecutive two array address value which store in the
physical address that points in the array to CX .
Examples
Save the number A787H in the physical memory location
11BA0H using registered relative addressing mode.
The physical address is 11BA0H. from the simulator
DS=700; offset is A10;
SO we can load A10H into BX like:
MOV BX, 0A10H;
MOV [BX+A190H], 0A787H;
Or we can load A10H into BX
MOV BX,0A10H
MOV [BX-A190H],0A787H;
4. Base-plus-index addressing
It moves a byte or word between a register and the memory location
addressed by a base register(BP or BX) plus an index register (DI or SI).
- The base register often holds the beginning location of a memory
array.
- Whereas , the index register holds the relative position of an
element in the array.
- When base pointer (BP) ,Stack segment is selected by default and
when BX addresses memory data segment is selected by default.
- Example
- MOV CX,[BX+DI]; Copies the word content of the data segment
memory location addressed by BX plus DI into CX.
- DS*10+BX+DICX
- MOV [BP+DI],AH; copies AH into stack segment memory location
addressed by BP plus DI.
- AHSS*10+BP+DI
Cont.
– The following figure shows locating data with base
plus index addressing mode.
Cont.
5. Base relative plus index addressing
• It transfers a byte or word between a register and a memory
location addressed by a base register(BP or BX) and an index
register (DI or SI) plus displacement.
• It similar to base plus index addressing , but it adds a displacement
beside using a base register and an index register.
• This type of addressing mode often address a two-dimensional
array of memory data.
• Example MOV DH,[BX+DI+20H];Copies the byte content of data
segment memory location addressed by the sum of BX,DI and 20H
into DH.
• MOV LIST[BP+DI],CL; Copies CL into the stack segment memory
location addressed by the sum of LIST ,BP and SI.
• MOV ARRAY[BX+SI],DX; DXDS*10+BX+SI+ARRAY
Cont.
– The following figure shows how data can be
accessed with relative plus index addressing modes.
Cont.
5. Base Relative Plus index addressing modes
– As mentioned on the previous slide, Base Relative Plus index
addressing modes is useful in addressing two dimensional
arrays. Two dimensional arrays usually stores records.
For example, student record such as its name, roll number etc….
– Each record on two dimensional arrays contains number of data
elements. To access data elements from a particular record we
use base register to hold the beginning address of the array of
records, index register to point a particular record in the array
of records and displacement to point a particular element in the
record. Figure on the next slide illustrates this content.
Base Relative Plus index addressing modes
– addressing two dimensional arrays.
Examples
Save the number A787H in the physical memory location
219C9H using base relative plus index addressing mode.
Answer: the physical address is 219C9H. from the simulator
DS=1700; so offset is A9C9; we can load A00 into BX and
9F00 into DI like:
MOV BX, 0A00H;
MOV DI,
9F00H;
MOV
(BX+DI+0C9H),
0A787H;
Or we can do it in a lot
Addressing modes For Accessing Memory
6. String Addressing Modes
– This mode uses index registers. The string instructions automatically
assume SI to point the first byte or word of the source operand and
DI to point to the first byte or word of the destination operand.
– The contents of SI and DI are automatically incremented (by
clearing DF to 0 by CLD instruction) or decremented (by setting DF
to 1 by STD instruction) to point to the next byte or word.
– The segment register for the source is DS. LA[DS:SI]
– The segment register for the destination must be ES. LA[ES:DI]
– The syntax is: MOVS BYTE
IF [DF]=0, [DS]=3000H, [SI]=0600H, [ES]=5000H,
[DI]=0400H,
[30600H]=38H and [50400H]=45H
Then after execution of the MOVS BYTE,
Addressing modes For Accessing I/O Ports
Standard I/O devices use port addressing modes.
To access the I/O port of the 8086 microprocessor ,port addressing
mode are used.
The port are accessed with IN and Out instructions
There are 2 types of port addressing modes:
– direct Port mode and
– Indirect Port mode
1. Direct port mode: here the port number is an 8 bit immediate
operand. This allows fixed access to port numbered 0 to 255.
Example:
OUT 05H, AL; this instruction sends the contents of AL to 8-bit port 05h;
IN AX, 80h; this instruction copies 16 bit contents of port 80h.
 Note: For IN and OUT instruction you can use only A register i.e AX,
AL, or AH
Addressing modes For Accessing I/O Ports
Example : Display the decimal number 5676 in the 8086
emulator LED(light emitting diode) display.
– Solution:
8086’s emulator is on port 199.
MOV AX, 5676;
OUT 199, AX;
Example : take an input from 8086’s simple input port and
display it
on the LED display.
8086’s has a simple 8 bit input at port 110 and 16
bit input at
port 112. so we can use one of them.
IN AX, 110;
Addressing modes For Accessing I/O Ports
Indirect Port Mode:
- The instruction will specify the name of the register which
holds the port address.
- In 8086,the 16-bit port address is stored in DX register.
– Here, the port number is taken from DX allowing 64K for 8 bit
ports or 32K for 16 bit ports.
Example
IN AL, DX ; if [DX]=7890H, then it copies 8 bit content of port
7890H into AL.
IN AX, DX; copies the 16 bit content of ports 7890H into AL
and AH respectively.
Note: the 8 bit and 16 bit I/O transfers must take place via AL
and
Addressing modes For Accessing I/O Ports
Example : Display the decimal number 5676 in the 8086
LED display by using Indirect Port Mode.
emulator
8086’s emulator is on port 199=C7H.
MOV DX, 0C7H;
MOV AX, 5676;
OUT DX,AX ;
Example : take an input
from 8086’s simple input
port and display it
on the LED display using
indirect port mode.
8086’s emulator
has a simple 8 bit
input at port
2. Program Memory Addressing modes
This mode involves program memory addressing
during various operations. It used in branch
instruction.
CALL and JUMP instructions used in this addressing
mode.
Example : JMP AX, In this instruction ,the code
execution control jumps to the current code
segment location addressed by the content of AX
register.
3 Type of Program Memory Addressing modes
A. Direct program memory addressing : in this addressing
mode the offset address where the control is to be
shifted is defined within the instruction.
Example: JMP 4032H
IP=4032 T0he current value of IP which holds the address of
the next instruction to be executed.
CS*10+4032H
B. Indirect program memory addressing : as the name
suggests ,the offset address is not present directly in the
instruction.
Example: JMP BX
Suppose that BX=0003H working of microprocessor BXIP
IP=0003H -(Content of CS)*10+(Content of IP)
Cont.
C.Relative program memory addressing :the offset address
is equal to the content of IP plus the 8 or 16-bit
Displacement. for 8-bit displacement, SHORT is used and
for 16-bit displacement LONG is used.
Example JMP SHORT OVER; SHORT is used to represent the
8- bit displacement and over is the label defined for any
particular memory location.
3. Stack Memory Addressing Modes
The stack is a portion of read/write memory set aside by the
user for the purpose of storing information temporarily.
When the information is written on the stack, the operation is
called PUSH.
When the information is read from the stack, the operation is
called a POP.
The stack pointer points to top of the stack.
The memory location currently pointed by stack pointer is
called top of the stack.
For stack operations: physical address is produced by adding
the content of stack segment register to the segment base
address in SS. Remember that segment base address is
multiplied by 10. This mode involves stack register operation
Stack Memory Addressing Modes
PUSH Instruction decrements stack pointer by two and
copies a word from some source to the location in the stack
where stack pointer points. The source is 16 bit wide.
Example: put the numbers 878H and 678AH on the stack. And
calculate SP.
– MOV AX, 878H;
– MOV CX, 678AH;
– PUSH AX;
– PUSH CX;
Example: put the numbers 878H, 6544H and 678AH on the stack. And see SP.
– MOV AX, 878H;
– MOV CX, 6544H;
– MOV DX, 678AH;
– PUSH AX;
– PUSH CX;
– PUSH DX;
Stack Memory Addressing Modes
POP Instruction copies a word from the stack location
pointed by the stack pointer to the destination. The
destination can be a general purpose register, a segment
register or memory location. After the word is copied to the
specified destination the stack pointer is automatically
incremented by 2.
Example: put the numbers D98H and 6B8AH on the stack. And pop it
on
the registers CX and BX.
– MOV AX, 878H;
– MOV CX, 678AH;
– PUSH AX;
– PUSH CX;
– POP CX;
– POP BX;
LED Display in Emulator
A LED (Light Emitting Display) is available in emu
8086 with port address 199.
It consist of 5 LED based display which can be used
to show number. (both positive and negative)
Example
1. Write a program that will subtract 6 from a numbers that is inputted by
a user and displays the result on the 8086’s LED display.
Solution :2^8=256 port address
IN AX, 112;
SUB AX, 6H;
OUT 199, AX;
2. Write a program that will subtract two numbers that is inputted by a
user and displays the result on the 8086’s LED display.
Solution: note: the program perform port 110- port 112
IN AX, 112;
MOV DL, AL;
IN AX, 110;
SUB AL, DL;
OUT 199, AL;
Example
3. Write a program that will take an input from port 112 increments it by one and
then subtract 7 from it and then display the result on 8086’s LED port.
Solution:
IN AX, 112;
INC AX;
SUB AX, 7H;
OUT 199, AX;
4. Write a program that will Multiply the numbers 12H and DFH and display the
result on LED display.
Solution
MOV AL, 12H;
MOV DL, 0DFH;
MUL DL;
OUT 199, AX;
Example
5. Write a program that divides the number ADC4H by EFH and displays
the result on the LED display.
Solution:
MOV AX, 0ADC4H;
MOV CL, 0EFH;
DIV CL;
MOV AH, 0H;
OUT 199, AX;;
Thank You

You might also like