Microcontroller
EL 302
Unit1
8086
Microprocessor
Gaurav Sharma
Topics Covered:
1.2 Instruction execution
sequence
1.3 Addressing modes
sequence
• In the 8086 microprocessor, the instructions
are executed in 4 steps which are listed as
follows:
o Fetch the instruction
o Decode the instruction
o Fetch the operands
o Execution of the instruction
Continued…
• For very large number of instructions this
process takes up a lot of time so to be efficient,
pipelining was introduced.
• 8086 has two functional units EU and BIU which
work mutually exclusive to each other.
• Due to this, the parallel processing of
instructions can be implied as:
Continued…
o Fetch instruction: Done by BIU
o Decode Instruction: Done by EU
o Fetch Operands: Done by BIU
o Execution: Done by EU
o So, while the instruction completes its first step
and goes to the second step that is handled by
the EU, the BIU is idle, and in that time, the next
instruction is fetched by BIU.
Continued…
• By doing so, the parallel processing of
instructions is implemented, and this concept is
known as pipelining.
Continued…
• So, it can be observed that the instructions
which were taking 12-time units for execution
while being processed in a sequential way are
now taking only 6 clock cycles through
pipelining.
Addressing Modes
• Every instruction of a program has to operate
on a data.
• The different ways in which a source operand is
denoted in an instruction are known as
addressing modes.
• There are 12 addressing modes in 8086.
Addressing Modes
1. Register Addressing
• The instruction will specify the name of the
register which holds the data to be operated by
the instruction.
• Example: MOV CL, DH: The content of 8-bit
register DH is moved to another 8-bit register
CL.
(CL) (DH)
2. Immediate Addressing
• In immediate addressing mode, an 8-bit or 16-
bit data is specified as part of the instruction.
• Example: MOV DL, 08H: The 8-bit data (08H)
given in the instruction is moved to DL.
(DL) 08H
• MOV AX, 0A9FH: The 16-bit data (0A9FH) given
in the instruction is moved to AX register.
(AX) 0A9FH
3. Direct Addressing
• Here, the effective address (offset
address) of the memory location at which
the data operand is stored is given in the
instruction.
• Example: MOV BX, [1354H]; MOV BL,
[0400H].
• The square brackets around the 1354H
denotes the contents of the memory
location. When executed, this instruction will
copy the contents of the memory location
into BX register.
Continued….
• This addressing mode is called direct because
the displacement of the operand from the
segment base is specified directly in the
instruction.
Addressing
• Name of the register which holds the effective
address (EA) will be specified in the instruction.
• Registers used to hold EA (effective or offset
address) are any of the following registers: BX,
BP, DI and SI.
• Content of the DS register is used for base
address calculation.
Continued…
• Example: MOV CX, [BX]
Effective Address EA = (BX)
Base Address BA = (DS) x 1016
Memory Address MA = BA + EA
(CX) (MA) or,
(CL) (MA)
(CH) (MA +1)
•
5. Based Addressing
• BX or BP is used to hold the base value for
effective address and a signed 8-bit or
unsigned 16-bit displacement will be
specified in the instruction.
• In case of 8-bit displacement, it is sign
extended to 16-bit before adding to the base
value.
• When BX holds the base value of EA, 20-bit
physical address is calculated from BX and
DS.
Continued…
• When BP holds the base value of EA, BP and SS
is used.
• Example: MOV AX, [BX + 08H]
0008H 08H (Sign extended)
EA = (BX) + 0008H
BA = (DS) x 1016
MA = BA + EA
(AX) (MA) or,
(AL) (MA)
(AH) (MA + 1)
6. Indexed Addressing
• SI or DI register is used to hold an index value
for memory data and a signed 8-bit or unsigned
16-bit displacement will be specified in the
instruction.
• Displacement is added to the index value in SI
or DI register to obtain the EA.
• In case of 8-bit displacement, it is sign
extended to 16-bit before adding to the base
value.
Continued…
• Example: MOV CX, [SI + A2H]
FFA2H A2H (Sign extended)
EA = (SI) + FFA2H
BA = (DS) x 1016
MA = BA + EA
(CX) (MA) or,
(CL) (MA)
(CH) (MA + 1)
Addressing
• In Based Index Addressing, the effective
address is computed from the sum of a base
register (BX or BP), an index register (SI or DI)
and a displacement.
Continued…
• Example: MOV DX, [BX + SI + 0AH]
000AH 0AH (Sign extended)
EA = (BX) + (SI) + 000AH
BA = (DS) x 1016
MA = BA + EA
(DX) (MA) or,
(DL) (MA)
(DH) (MA + 1)
8. String Addressing
• Employed in string operations to operate on
string data.
• The effective address (EA) of source data is
stored in SI register and the EA of destination is
stored in DI register.
• Segment register for calculating base address
of source data is DS and that of the destination
data is ES.
Continued…
•Example: MOVS BYTE
Calculation of source memory location:
EA = (SI) BA = (DS) x 1016 MA = BA + EA
Calculation of destination memory location:
EAE = (DI) BAE = (ES) x 1016 MAE = BAE +
EAE
(MAE) (MA)
If DF = 1, then (SI) (SI) – 1 and (DI) = (DI) - 1
Addressing
• This addressing mode is used to access data
from standard I/O mapped devices or ports.
• In this mode, an 8-bit port address is directly
specified in the instruction.
•Example: IN AL, [09H]
PORT addr = 09
(AL) (PORT)
Content of port with address 09H is moved to AL
register
Addressing
• If we use 16-bit I/O address we get a range of
0000H--FFFFH. This gives a total of 65536 I/O
ports. Here we use Indirect addressing Mode,
that is, the I/O address is specified by DX
register.
• This is also called Variable Port Addressing.
Continued…
• Example: MOV DX, 2080H
IN AL, DX ; AL gets data from I/O port
address 2080H given by DX.
OUT DX, AL ; I/O port whose address is given
by DX gets 8-bit data from AL
11. Relative Addressing
o In this addressing mode, the effective address
of a program instruction is specified relative to
Instruction Pointer (IP) by an 8-bit signed
displacement.
Continued…
• Example: JZ 0AH
000AH 0AH (sign extend)
If ZF = 1, then
EA = (IP) + 000AH
BA = (CS) x 1016
MA = BA + EA
If ZF = 1, then the program control jumps to
new address calculated above.
If ZF = 0, then next instruction of the program
is executed.
12. Implied Addressing
• Instructions using this mode have no operands.
The instruction itself will specify the data to be
operated by the instruction.
• Example: CLC
This clears the carry flag to zero.
THANK YOU