Unit I The 8086 Microprocessor
Unit I The 8086 Microprocessor
8085 Microprocessor:
8085 is pronounced as "eighty-eighty-five" microprocessor. It is an 8-bit microprocessor
designed by Intel in 1977 using NMOS technology.
It has the following configuration −
8-bit data bus
16-bit address bus, which can address upto 64KB
A 16-bit program counter
A 16-bit stack pointer
Six 8-bit registers arranged in pairs: BC, DE, HL
Requires +5V supply to operate at 3.2 MHZ single phase clock
It is used in washing machines, microwave ovens, mobile phones, etc.
S Z AC P CY
Sign Flag (S) – After any operation if the MSB (B(7)) of the result is 1, it in indicates the
number is negative and the sign flag becomes set, i.e. 1. If the MSB is 0, it indicates the
number is positive and the sign flag becomes reset i.e. 0.
Zero Flag (Z) – After any arithmetical or logical operation if the result is 0 (00)H, the zero
flag becomes set i.e. 1, otherwise it becomes reset i.e. 0.
Auxiliary Cary Flag (AC) – This flag is used in BCD number system(0-9). If after any
arithmetic or logical operation D(3) generates any carry and passes on to B(4) this flag
becomes set i.e. 1, otherwise it becomes reset i.e. 0.
Parity Flag (P) – If after any arithmetic or logical operation the result has even parity, an
even number of 1 bits, the parity register becomes set i.e. 1, otherwise it becomes reset i.e. 0.
Carry Flag (CY) – Carry is generated when performing n bit operations and the result is
more than n bits, then this flag becomes set i.e. 1, otherwise it becomes reset i.e. 0.
Flags Register determines the current state of the processor. They are modified automatically
by CPU after mathematical operations, this allows to determine the type of the result, and to
determine conditions to transfer control to other parts of the program. 8086 has 9 flags and
they are divided into two categories:
Carry Flag (CF): This flag indicates an overflow condition for unsigned integer
arithmetic. 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 and for odd
number of 1’s, the Parity Flag is reset.
Zero Flag (ZF): It is set; 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.
Overflow Flag (OF): It occurs when signed numbers are added or subtracted. An OF
indicates that the result has exceeded the capacity of machine.
Trap Flag (TP):
a. It is used for single step control.
b. It allows user to execute one instruction of a program at a time for debugging.
Interrupt Flag (IF):
a. It is an interrupt enable/disable flag.
b. If it is set, the maskable interrupt of 8086 is enabled and if it is reset, the
interrupt is disabled.
Direction Flag (DF):
a. It is used in string operation.
b. If it is set, string bytes are accessed from higher memory address to lower
memory address.
SI - source index register:
o Can be used for pointer addressing of data
o Used as source in some string processing instructions
o Offset address relative to DS
DI - destination index register:
o Can be used for pointer addressing of data
o Used as destination in some string processing instructions
o Offset address relative to ES
BP - base pointer:
o Primarily used to access parameters passed via the stack
o Offset address relative to SS
SP - stack pointer:
o Always points to top item on the stack
o Offset address relative to SS
o Always points to word (byte at even address)
o An empty stack will had SP = FFFEh
REGISTER ORGANIZATION
a) General Registers
b) Index Registers
c) Segment Registers
d) Pointer Registers
e) Status Register
A register is a very small amount of fast memory that is built in the CPU (or Processor) in
order to speed up the operation. Register is very fast and efficient than the other memories
like RAM, ROM, external memory etc,. That’s why the registers occupied the top position in
memory hierarchy model.
The 8086 microprocessor has a total of fourteen registers that are accessible to the
programmer. All these registers are 16-bit in size. The registers of 8086 are categorized into 5
different groups.
a) General registers
b) Index registers
c) Segment registers
d) Pointer registers
e) Status Register
d) General Registers
All general registers of the 8086 microprocessor can be used for arithmetic and logic
operations. These all general registers can be used as either 8-bit or 16-bit registers. The
general registers are:
i. AX (Accumulator):
AX is used as 16-bit accumulator. The lower 8-bits of AX are designated to use as AL
and higher 8-bits as AH. AL can be used as an 8-bit accumulator for 8-bit operation.
This Accumulator used in arithmetic, logic and data transfer operations. For manipulation
and division operations, one of the numbers must be placed in AX or AL.
ii. BX (Base Register):
BX is a 16 bit register, but BL indicates the lower 8-bits of BX and BH indicates the
higher 8-bits of BX. The register BX is used as address register to form physical address
in case of certain addressing modes (ex: indexed and register indirect).
iii. CX (Count Register):
The register CX is used default counter in case of string and loop instructions. Count
register can also be used as a counter in string manipulation and shift/rotate instruction.
iv. DX (Data Register):
DX register is a general purpose register which may be used as an implicit operand or
destination in case of a few instructions. Data register can also be used as a port number
in I/O operations.
e) Segment Register:
The 8086 architecture uses the concept of segmented memory. 8086 can able to access a
memory capacity of up to 1 megabyte. This 1 megabyte of memory is divided into 16 logical
segments. Each segment contains 64 Kbytes of memory. This memory segmentation concept
will discuss later in this document.
There are four segment registers to access this 1 megabyte of memory. The segment registers
of 8086 are:
i. CS (Code Segment):
Code segment (CS) is a 16-bit register that is used for addressing memory location in the
code segment of the memory (64Kb), where the executable program is stored. CS register
cannot be changed directly. The CS register is automatically updated during far jump, far
call and far return instructions.
ii. Stack segment (SS)
Stack Segment (SS) is a 16-bit register that used for addressing stack segment of the
memory (64kb) where stack data is stored. SS register can be changed directly using POP
instruction.
iii. Data segment (DS)
Data Segment (DS) is a 16-bit register that points the data segment of the memory (64kb)
where the program data is stored. DS register can be changed directly using POP and LDS
instructions.
iv. Extra segment (ES):
Extra Segment (ES) is a 16-bit register that also points the data segment of the memory
(64kb) where the program data is stored. ES register can be changed directly using POP
and LES instructions.
f) Index Registers
The index registers can be used for arithmetic operations but their use is usually concerned
with the memory addressing modes of the 8086 microprocessor (indexed, base indexed and
relative base indexed addressing modes).
The index registers are particularly useful for string manipulation.
i. SI (Source Index):
SI is a 16-bit register. This register is used to store the offset of source data in data
segment. In other words the Source Index Register is used to point the memory locations
in the data segment.
ii. DI (Destination Index):
DI is a 16-bit register. This is destination index register performs the same function as SI.
There is a class of instructions called string operations that use DI to access the memory
locations in Data or Extra Segment.
g) Pointer Registers:
Pointer Registers contains the offset of data(variables, labels) and instructions from their base
segments (default segments).8086 microprocessor contains three pointer registers.
i. SP (Stack Pointer):
Stack Pointer register points the program stack that means SP stores the base address of
the Stack Segment.
ii. BP (Base Pointer):
Base Pointer register also points the same stack segment. Unlike SP, we can use BP to
access data in the other segments also.
iii. IP (Instruction Pointer):
The Instruction Pointer is a register that holds the address of the next instruction to be
fetched from memory.It contains the offset of the next word of instruction code instead of
its actual address
h) Status Register:
The status register also called as flag register. The 8086 flag register contents indicate the
results of computation in the ALU. It also contains some flag bits to control the CPU
operations.
Flag register is 16-bit register with only nine bits that are implemented. Six of these are status
flags. The complete bit configuration of 8086 is shown in the figure.
To be able to program a microprocessor, one does not need to know all of its
hardware architectural features. What is important to the programmer is being aware of
the various registers within the device and to understand their purpose, functions,
operating capabilities, and limitations.
The above figure illustrates the software architecture of the 8086 microprocessor.
From this diagram, we see that it includes fourteenl6-bit internal registers: the instruction
pointer (IP), four data registers (AX, BX, CX, and DX), two pointer registers (BP and
SP), two index registers (SI and DI), four segment registers (CS, DS, SS, and ES) and
status register (SR), with nine of its bits implemented as status and control flags.
The point to note is that the beginning segment address must begin at an address
divisible by 16.Also note that the four segments need not be defined separately. It is
allowable for all four segments to completely overlap (CS = DS = ES = SS).
Logical and Physical Address
Addresses within a segment can range from address 00000h to address 0FFFFh.
This corresponds to the 64K-bytelength of the segment. An address within a segment is
called an offset or logical address.
A logical address gives the displacement from the base address of the segment to
the desired location within it, as opposed to its "real" address, which maps directly
anywhere into the 1 MByte memory space. This "real" address is called the physical
address.
The physical address is 20 bits long and corresponds to the actual binary code
output by the BIU on the address bus lines. The logical address is an offset from location
0 of a given segment.
You should also be careful when writing addresses on paper to do so clearly. To specify
the logical address XXXX in the stack segment, use the convention SS:XXXX, which is
equal to [SS] * 16 + XXXX.
Example:
The value of Data Segment Register (DS) is 2222H.
To convert this 16-bit address into 20-bit, the BIU appends 0H to the LSB (by multiplying
with 16) of the address. After appending, the starting address of the Data Segment
becomes 22220H.
Data at any location has a logical address specified as:2222H: 0016H
Where 0016H is the offset, 2222 H is the value of DS
Therefore the physical address:22220H + 0016H: 22236 H
The following tables describes the default offset values to the corresponding memory
segments.
The above figure represents: storage location of address 0000916 contains the value 716,
while the location of address 0001016 contains the value 7D16. The 16-bit word 225A16is
stored in the locations 0000C16 to 0000D16
The word of data is at an even-address boundary (i.e. address of least significant byte is even)
is called aligned word. The word of data is at an odd-address boundary is called misaligned
word, as shown in Figure below.
To store double word four locations are needed. The double word that it’s least significant
byte address is a multiple of 4 (e.g. 0 16, 416, 816 ...) is called aligned double word. The
double word at address of non-multiples of 4 is called misaligned double word shown in
Figure below.
0 0 No operation
0 0 0 Interrupt acknowledgement
0 0 1 I/O Read
0 1 0 I/O Write
0 1 1 Halt
1 0 0 Opcode fetch
1 0 1 Memory read
1 1 0 Memory write
1 1 1 Passive
____
LOCK
When this signal is active, it indicates to the other processors not to ask the CPU to leave the
system bus. It is activated using the LOCK prefix on any instruction and is available at pin
29.
___ ___ ___ ___
RQ/GT1 and RQ/GT0
These are the Request/Grant signals used by the other processors requesting the CPU to
release the system bus. When the signal is received by CPU, then it sends acknowledgment.
RQ/GT0 has a higher priority than RQ/GT1.
Comparison between Minimum & Maximum mode
Minimum mode Maximum mode
In minimum mode there can be only one In maximum mode there can be multiple processors
processor i.e. 8086. with 8086, like 8087 and 8089.
___ ___
MN/MX is 1 to indicate minimum mode. MN/MX is 0 to indicate maximum mode.
ALE for the latch is given by 8086 as it is the ALE for the latch is given by 8288 bus controller as
only processor in the circuit. there can be multiple processors in the circuit.
____ _ ____ _
DEN and DT/R for the trans-receivers are DEN and DT/R for the trans-receivers are given by
given by 8086 itself. 8288 bus controller.
__ __ ___ __ __ __
M/IO, RD and WR are decoded by a 3:8 Status signal called S2, S1and S0.are decoded by a
decoder like 74138. bus controller like 8288 to produce control signals.
____ ____
INTA is given by 8086 in response to an INTA is given by 8288 bus controller in response to
interrupt on INTR line. an interrupt on INTR line.
TIMING DIAGRAM
Timing Diagram is a graphical representation. It represents the execution time taken
by each instruction in a graphical format. The execution time is represented in T-states.
Hardware Interrupts
Hardware interrupt is caused by any peripheral device by sending a signal through a
specified pin to the microprocessor.
The 8086 has two hardware interrupt pins, i.e. NMI and INTR. NMI is a non-maskable
interrupt and INTR is a maskable interrupt having lower priority.
NMI
It is a single non-maskable interrupt pin (NMI) having higher priority than the maskable
interrupt request pin (INTR) and it is of type 2 interrupt.
When this interrupt is activated, these actions take place −
Completes the current instruction that is in progress.
Pushes the Flag register values on to the stack.
Pushes the CS (code segment) value and IP (instruction pointer) value of the return
address on to the stack.
IP is loaded from the contents of the word location 00008H.
CS is loaded from the contents of the next word location 0000AH.
Interrupt flag and trap flag are reset to 0.
INTR
The INTR is a maskable interrupt because the microprocessor will be interrupted only if
interrupts are enabled using set interrupt flag instruction. It should not be enabled using clear
interrupt Flag instruction.
The INTR interrupt is activated by an I/O port. If the interrupt is enabled and NMI is
disabled, then the microprocessor first completes the current execution and sends ‘0’ on
INTA pin twice. The first ‘0’ means INTA informs the external device to get ready and
during the second ‘0’ the microprocessor receives the 8 bit, say X, from the programmable
interrupt controller.
These actions are taken by the microprocessor −
First completes the current instruction.
Activates INTA output and receives the interrupt type, say X.
Flag register value, CS value of the return address and IP value of the return address
are pushed on to the stack.
IP value is loaded from the contents of word location X × 4
CS is loaded from the contents of the next word location.
Interrupt flag and trap flag is reset to 0
Software Interrupts
Some instructions are inserted at the desired position into the program to create interrupts.
These interrupt instructions can be used to test the working of various interrupt handlers. It
includes −