8086 Unit - II
8086 Unit - II
8086 MICROPROCESSOR
2.1 Introduction
The 8086 is a 16-bit microprocessor intended to be used as the CPU in a
microcomputer. The term “16-bit” means that its arithmetic logic unit, internal
registers, and most of its instructions are designed to work 16-bit binary words.
It has 16-bit data bus and 20-bit address bus.
Words will be stored in two consecutive memory locations. If the first byte
of a word is at an even address, the 8086 can read the entire word in one
operation. If the first byte of the word is at an odd address, the 8086 will read
the first byte in one operation, and the second byte in another operation.
Features
● 8086 is a 40 pin IC.
● It is a 16-bit processor.
● Its operating voltage is 5 volts.
● Its operating frequency is 5 MHz
● The total memory addressing capacity is 1MB (external).
● It has 16-bit data bus and 20-bit address bus.
● It has fourteen 16-bit registers.
● It has around 20000 transistors in its circuitry and it is made in
HMOS technology.
● Pipelining improves the performance of the processor so that
operation is faster.8086 uses two stage of pipelining.
● First is Fetch Stage and the second is Execute Stage.
● Fetch stage that prefetch upto 6 bytes of instructions stores them in
the queue.
● Execute stage that executes these instructions.
● Operates in two modes: 8086 operates in two modes:
AD15-AD0
These are the time multiplexed memory I/O address and data lines.
Address remains on the lines during T1 state, while the data is available on the
data bus during T2, T3, TW and T4. Here T1, T2, T3, T4 and TW are the clock
states of a machine cycle. TW is a wait state. These lines are active high and
float to a tristate during interrupt acknowledge and local bus hold acknowledge
cycles.
A19/S6, A18/S5, A17/S4, A16/S3: These are the time multiplexed
address and status lines. During T1, these are the most significant address lines
or memory operations. During I/O operations, these lines are low. During
memory or I/O operations, status information is available on those lines for T2,
T3, TW and T4.The status of the interrupt enable flag bit(displayed on S5) is
updated at the beginning of each clock cycle. The S4 and S3 combined, indicate
which segment register is presently being used for memory accesses as shown
in the following table.These lines float to tri-state off during the local bus hold
acknowledge. The status line S6 is always low(logical). The address bits are
separated from the status bits using latches controlled by the ALE signal.
Table 2.1 Segment Register Indication
S S Indication
4 3
0 0 Alternate
data
0 1 Stack
1 0 Code or none
Microprocessor and Microcontroller
1 1 Data
RD-Read: Read signal, when low, indicates the peripherals that the
processor is performing a memory or I/O read operation. RD is active low and
shows the state for T2, T3, TW of any read cycle. The signal remains in high-
impedance during the 'hold acknowledge'.
Ready: This is the acknowledgement from the slow devices or memory that
they have completed the data transfer. The signal made available by the devices
is synchronized by the 8284A clock generator to provide ready input to the
8086. The signal is active high.
TEST: This input is examined by a 'WAIT' instruction. If the TEST input goes
low, execution will continue, else, the processor remains in an idle state. The
input is synchronized internally during each clock cycle on leading edge of
clock.
Reset: This input causes the processor to terminate the current activity and
start execution from FFFF0H. The signal is active high and must be active for at
least four clock cycles. It restarts execution when the RESET returns low. RESET
is also internally synchronized.
CLK-Clock Input: The clock input provides the basic timing for processor
operation and bus control activity. It’s an asymmetric square wave with 33%
duty cycle. The range of frequency for different 8086 versions is from 5MHz to
10MHz.
VCC : +5V power supply for the operation of the internal circuit. GND
ground for the internal circuit.
MN/MX: The logic level at this pin decides whether the processor is to
operate in either minimum (single processor) or maximum (multiprocessor)
mode.
The following pin functions are for the minimum mode operation of 8086.
DEN-Data Enable This signal indicates the availability of valid data over
the address/data lines. It is used to enable the transceivers (bidirectional
Microprocessor and Microcontroller
S2, S1, S0 -Status Lines: These are the status lines which reflect the type of
operation, being carried out by the processor. These become active during T4 of
the previous cycle and remain active during T1 and T2 of the current bus cycle.
The status lines return to passive state during T3 of the current bus cycle so
that they may again become active for the next bus cycle during T4. Any change
in these lines during T3 indicates the starting of a new cycle, and return to
passive state indicates end of the bus cycle. These status lines are encoded in
the following table.
Table 2.3 Status Lines Indication
S S S Indication
2 1 0
0 0 0 Interrupt
acknowledge
0 0 1 Read I/O port
0 1 0 Write I/O port
0 1 1 Halt
1 0 0 Code access
1 0 1 Read memory
1 1 0 Write memory
1 1 1 Passive
Lock
This output pin indicates that other system bus masters will be prevented
from gaining the system bus, while the LOCK signal is low. The LOCK signal is
activated by the 'LOCK' prefix instruction and remains active until the
completion of the next instruction. This floats to tri-state off during "hold
acknowledge". When the CPU is executing a critical instruction, which requires
the system bus, the LOCK prefix instruction ensures that other processors
connected in the system will not gain the control of the bus. The 8086, while
executing the prefixed instruction, asserts the bus lock signal output, which
may be connected to an external bus controller.
from 8086 to the requesting master, indicates that the 8086 has
allowed the local bus to float and that it will enter the "hold
acknowledge" state at next clock cycle. The CPU's bus interface unit
is likely to be disconnected from the local bus of the system.
3. A one clock wide pulse from another master indicates to 8086 that
the 'hold' request is about to end and the 8086 may regain control
of the local bus at the next clock cycle. Thus, each master to master
exchange of the local bus is a sequence of 3 pulses. There must be at
least one dead clock cycle after each bus exchange. The request and
grant pulses are active low. For the bus requests those are received
while 8086 is performing memory or I/O cycle, the granting of the
bus is governed by the rules of HOLD, and HLDA in minimum mode.
Instruction Queue
To increase the execution speed, BIU fetches as many as six instruction
bytes ahead to time from memory. The prefetched instruction bytes are held for
the EU in a first in first out group of registers called an instruction queue. When
the EU is ready for its next instruction, it simply reads the instruction from this
instruction queue. This is much faster than sending out an address to the
system memory and to send back the next instruction byte. Fetching the next
instruction while the current instruction executes is called pipelining.
Fig 2.2 Block Diagram
Microprocessor and Microcontroller
Segment Registers
The BIU contains four 16-bit segment registers. They are: the extra segment
(ES) register, the code segment (CS) registers, the data segment (DS) registers,
and the stack segment (SS) registers. These segment registers are used to hold
the upper 16 bits of the starting address for each of the segments. The part of a
segment starting address stored in a segment register is often called the
segment base.
1. Code Segment (CS): The CS register is used for addressing a memory
location in the Code Segment of the memory, where the executable
program is stored.
2. Data Segment (DS): The DS contains most data used by program. Data
are accessed in the
Data Segment by an offset address or the content of other register that
holds the offset address.
3. Stack Segment (SS): SS defined a section of memory to store addresses
and data while a subprogram executes.
4. Extra Segment (ES): ES is additional data segment that is used by some
of the string to hold the extra destination data.
Flag Register
A 16-bit flag register is a flip-flop which indicates some condition produced
by the execution of an instruction or controls certain operations of the EU. They
are modified automatically by CPU after mathematical operations. It has 9 flags
and they are divided into two categories:
1. Conditional Flags
2. Control Flags
Conditional Flags
Conditional flags represent result of last arithmetic or logical instructions.
● Carry Flag (CF): This flag will be set to one if the arithmetic
operation produces the carry in MSB position. It is also used in
multiple-precision arithmetic.
● Auxiliary Flag (AF): If an operation performed in ALU generates a
carry/barrow from lower nibble (i.e. D0 – D3) to upper nibble (i.e.
D4 – D7), the AF flag is set i.e. carry given by D3 bit to D4 is AF flag.
This is not a general-purpose flag; it is used internally by the
processor to perform Binary to BCD conversion.
● Parity Flag (PF): This flag is used to indicate the parity of result. If
lower order 8-bits of the result contains even number of 1’s, the
Parity Flag is set to one and for odd number of 1’s, the Parity Flag is
reset i.e. zero.
● Zero Flag (ZF): It is set to one; if the result of arithmetic or logical
operation is zero else it is reset.
● Sign Flag (SF): In sign magnitude format the sign of number is
indicated by MSB bit. If the result of operation is negative, sign flag
is set to one.
Microprocessor and Microcontroller
Control Flags
Control flags are intentionally set or reset to control certain operations of
the processor with specific instructions put in the program from the user.
Control flags are as follows:
1. Trap Flag (TF): It is used for single step control. It allows user to
execute one instruction of a program at a time for debugging. When
trap flag is set, program can be run in single step mode.
2. Interrupt Flag (IF): It is an interrupt enable/disable flag, i.e. used
to allow/prohibit the interruption of a program. If it is set, the
maskable interrupt is enabled and if it is reset, the interrupt is
disabled.
3. Direction Flag (DF): It is used in string operation. If it is set, string
bytes are accessed from higher memory address to lower memory
address. When it is reset, the string bytes are accessed from lower
memory address to higher memory address.
Example 1
MOV CL, 03 H
Moves the 8-bit data 03 H into CL
Example 2
MOV DX, 0525 H
Moves the 16-bit data 0525 H into DX
In the above two examples, the source operand is in immediate mode and
the destination operand is in register mode.
A constant such as “VALUE” can be defined by the assembler EQUATE
directive such as VALUE EQU 35H
Example
MOV BH, VALUE
Used to load 35 H into BH
Example 2
MOV CL, DL
Moves 8-bit contents of DL into CL
MOV BX, CH is an illegal instruction.
* The register sizes must be the same.
The Execution Unit (EU) has direct access to all registers and data for
register and immediate operands. However, the EU cannot directly access the
memory operands. It must use the BIU, in order to access memory operands. In
the direct addressing mode, the 16-bit effective address (EA) is taken directly
from the displacement field of the instruction.
Example 1
MOV CX, START
If the 16-bit value assigned to the offset START by the programmer using an
assembler pseudo instruction such as DW is 0040 and [DS] = 3050.
Then BIU generates the 20-bit physical address 30540 H.
The content of 30540 is moved to CL
The content of 30541 is moved to CH
Microprocessor and Microcontroller
Example 2
MOV CH, START
If [DS] = 3050 and START = 0040
8-bit content of memory location 30540 is moved to CH.
Example 3
MOV START, BX
With [DS] = 3050, the value of START is 0040.
Physical address: 30540
MOV instruction moves (BL) and (BH) to locations 30540 and 30541
respectively.
Example
MOV [DI], BX
register indirect
If [DS] = 5004, [DI] = 0020, [Bx] = 2456 PA=50060.
The content of BX (2456) is moved to memory locations 50060 H and
50061 H.
Example
MOV BH, START [SI]
PA: [SART] + [SI] + [DS]
The content of this memory is moved into BH.
Example
MOV ALPHA [SI] [BX], CL
If [BX] = 0200, ALPHA – 08, [SI] = 1000 H and [DS] = 3000
Physical address (PA) = 31208
8-bit content of CL is moved to 31208 memory address.
Example
MOV S BYTE
If [DF] = 0, [DS] = 2000 H, [SI] = 0500,
[ES] = 4000, [DI] = 0300
Source address: 20500, assume it contains 38
Microprocessor and Microcontroller
I/O mode
Direct Mode
Port number is an 8-bit immediate operand.
Example: OUT 05H, AL
Outputs [AL] to 8-bit port 05 H
Indirect Mode
The port number is taken from DX.
Example 1
INAL, DX
If [DX] = 5040
8-bit content by port 5040 is moved into AL.
Example 2
IN AX, DX
Inputs 8-bit content of ports 5040 and 5041 into AL and AH respectively.
Logical Instructions
Microprocessor and Microcontroller
Arithmetic Instructions
Call and Return Instructions
Microprocessor and Microcontroller
String Instructions