Unit-2 8086 Microprocessor
Unit-2 8086 Microprocessor
1
>20,000
2
Architecture
3
Bus Interface Unit (BIU)
BIU fetches instructions, reads data from memory and I/O ports, writes data to
memory and I/ O ports.
4
Register Organization of 8086
5
8086 Microprocessor Architecture Execution Unit (EU)
6
8086 Microprocessor Architecture Execution Unit (EU)
7
8086 Microprocessor Architecture Execution Unit (EU)
EU
Registers
9
10
11
8086 Microprocessor Architecture Execution Unit (EU)
Auxiliary Carry Flag Carry Flag
This is set, if there is a carry from the
Flag Register lowest nibble, i.e, bit three during
This flag is set, when there is a
carry out of MSB in case of
addition, or borrow for the lowest nibble, addition or a borrow in case of
i.e, bit three, during subtraction. subtraction.
Sign Flag Zero Flag Parity Flag
This flag is set, when the This flag is set, if the result of This flag is set to 1, if the lower
result of any computation the computation or comparison byte of the result contains even
is negative performed by an instruction is number of 1’s ; for odd number
zero of 1’s set to zero.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OF DF IF TF SF ZF AF PF CF
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OF DF IF TF SF ZF AF PF CF
AX 16-bit Accumulator Stores the 16-bit results of arithmetic and logic operations
AL 8-bit Accumulator Stores the 8-bit results of arithmetic and logic operations
BX Base register Used to hold base value in base addressing mode to access
memory data
CX Count Register Used to hold the count value in SHIFT, ROTATE and LOOP
instructions
DX Data Register Used to hold data for multiplication and division operations
SP Stack Pointer Used to hold the offset address of top stack memory
BP Base Pointer Used to hold the base value in base addressing using SS register to
access data from stack memory
SI Source Index Used to hold index value of source operand (data) for string
instructions
DI Data Index Used to hold the index value of destination operand (data) for
string operations 14
Types of addressing mode in 8086
1. Immediate addressing mode
2. Direct addressing mode
3. Register addressing mode
4. Register Indirect addressing mode
5. Indexed addressing mode
6. Register relative addressing mode
7. Base plus index addressing mode
8. Base relative plus index addressing mode
1: Immediate addressing mode
10 ABH
MOV AX,10ABH AX
2: Direct addressing mode
AX
3: Register addressing mode
BX
50 00
Reflection Spot
MOV [7000H],CX
Q) Which addressing does instruction above belong,
and why?
Reflection Spot
MOV [7000H],CX
Q) Which addressing does instruction above
belonging and why?
Memory
Ans) Direct addressing mode 22 7000
33 7001
7002
CX 43 56
5: Indexed addressing mode
50 00 SI
6: Register relative addressing mode
50 00 + 50H = 5050H
Final
Index
BX Offset Address
7: Base plus index addressing mode
10 00 + 20 00 = 3000H
Final
BX SI Index
Address
8: Base relative plus index addressing mode
50H + 10 00 20 00 = 3050H
Final
BX SI Index
Address
1
Instruction Set of 8086
An instruction is a binary pattern designed
inside a microprocessor to perform a specific
function.
The entire group of instructions that a
microprocessor supports is called
Instruction Set.
8086 has more than 20,000 instructions.
2
Classification of Instruction Set
1. Data Move/Transfer Instructions
2. Arithmetic Instructions and Logical Instruction
3. Shift and Rotate Instruction
4. Branch and Loop Instruction
5. M/C control Instruction
6. Flag Manipulation Instructions
7. String Instructions
3
1. Data Transfer Instructions
4
Data Transfer Instructions
MOV Des, Src:
It is used to copy the content of Src to Des
Src operand can be register, memory location or immediate operand.
Des can be register or memory operand.
Both Src and Des cannot be memory location at the same time(except
for string instructions).
Transferring immediate data to segment register is not possible i.e
MOV DS, 5000H ; Not permitted
MOV AX, 5000H
MOV DS, AC
E.g.:
MOV CX, 037A H
MOV AL, BL
MOV BX, [0301 H] 5
Data Transfer Instructions
PUSH Operand:
It pushes the operand into top of stack.
E.g.: PUSH AX
SP is decremented by 2
• POP Des:
It pops the operand from top of stack to Des.
Des can be a general purpose register, segment register (except CS)
or memory location.
E.g.: POP AX
SP is incremented by 2
6
Data Transfer Instructions
7
Data Transfer Instructions
IN Accumulator, Port Address:
It transfers the operand from specified port to accumulator
register.
8
Data Transfer Instructions
LEA Register, Src:
9
Data Transfer Instructions
LAHF:
It copies the lower byte of flag register to AH.
SAHF:
It copies the contents of AH to lower byte of flag register.
PUSHF:
Pushes flag register to top of stack. (first Upper byte,
then lower byte)
POPF:
Pops the stack top to flag register. (First lower byte, then
upper byte)
10
1. Arithmetic And Logical
Instructions
Arithmetic Instructions
ADD Des, Src:
It adds a byte to byte or a word to word.
It effects AF, CF, OF, PF, SF, ZF flags.
Both operands can’t be Memory locations
E.g.:
ADD AL, 74H
ADD DX, AX
ADD AX, [BX]; Reg indirect
ADD 0100H; implicit AX
12
Arithmetic Instructions
ADC Des, Src:
It adds the two operands with CF, which was set
by previous calculations.
It effects AF, CF, OF, PF, SF, ZF flags.
E.g.:
ADC AL, 74H
ADC DX, AX
ADC AX, [BX]
ADC 0100H
21-Nov-2010 [email protected] 13
Arithmetic Instructions
INC : Increment
It will increment the content of specified reg./memloc. by 1.
Here all the condition code flags are affected except CF
Immediate data can’t be operand for this instruction
Ex INC AX INC [BX] INC [5000H]
• DEC : Decrement
It will decrement the content of specified reg./memloc. by 1.
Here all the condition code flags are affected except CF
Immediate data can’t be operand for this instruction
Ex DEC AX DEC [BX] DEC [5000H]
14
Arithmetic Instructions
SUB Des, Src:
Subtracts the src operand from destination operand and
result is left in des operand
It subtracts a byte from byte or a word from word.
It effects AF, CF, OF, PF, SF, ZF flags.
For subtraction, CF acts as borrow flag.
E.g.:
SUB AL, 74H
SUB DX, AX
SUB AX, [BX]
SUB 0100H 15
Arithmetic Instructions
SBB Des, Src:
It subtracts the two operands and also the
borrow, which was set by previous calculations.
It effects AF, CF, OF, PF, SF, ZF flags.
E.g.:
SBB AL, 74H
SBB DX, AX
SBB AX, [BX]
SBB 0100H
16
Arithmetic Instructions
MUL Src:
It is an unsigned multiplication instruction.
It multiplies two bytes to produce a word or two words to
produce a double word.
AX = AL * Src
DX : AX = AX * Src
MUL CX ; (DX)(AX)<-(AX)*(CX)
This instruction assumes one of the operand in AL or AX.
Src can be a register or memory location. And Flags-OF, CF
Unused bits of destination register is always filled with sign bit
IMUL Src:
It is a signed multiplication instruction.
21-Nov-2010 [email protected] 17
Arithmetic Instructions
DIV Src:
It is an unsigned division instruction.
It divides word by byte or double word by word.
The operand is stored in AX, divisor is Src and
the result is stored as:
AH = remainder, AL = quotient (for word/byte)
DX=remainder, AX=quotient (for D-word/word)
IDIV Src:
It is a signed division instruction.
21-Nov-2010 [email protected] 18
Arithmetic Instructions
CMP: compare
NEG Src:
25
Branch Instructions
CALL Des:
This instruction is used to call a subroutine or function
or procedure.
The address of next instruction after CALL is saved onto
stack.
RET:
It returns the control from procedure to calling program.
Every CALL instruction should have a RET.
26
Branch Instructions
JMP Des:
This instruction is used for unconditional jump from
one place to another.
27
Conditional Jump Table
Mnemonic Meaning Jump Condition
JB Jump if Below CF = 1
JC Jump if Carry CF = 1
JE Jump if Equal ZF = 1
29
ASSUME: Assume Logical Segment Name
The ASSUME directive is used to inform
the as- semble, the names of the logicals
segments to be assumed for different
segments used in the program. In the
assembly language program, each
segment is given a name. For example, the
code segment may be given the name
CODE, data segment may be given the
name DATA etc. The statement ASSUME
CS: CODE directs the assembler that the
machine codes are available in a segment
named CODE, and hence the CS register
is to be loaded with the address (segment)
allotted by the operating system for the
label CODE, while loading.
UNIT -V
Interrupts in 8086 Microprocessor
Interrupts
Definition: The meaning of ‘interrupts’ is to break the sequence of operation. While the CPU
is executing a program, on ‘interrupt’ breaks the normal sequence of execution of
instructions, diverts its execution to some other program called Interrupt Service Routine
(ISR).After executing ISR , the control is transferred back again to the main program.
Interrupt processing is an alternative to polling.
Need for Interrupt: Interrupts are particularly useful when interfacing I/O devices that
provide or require data at relatively low data transfer rate.
When an interrupt occurs, the processor stores FLAGS register into stack, disables
further interrupts, fetches from the bus one byte representing interrupt type, and jumps
to interrupt processing routine address of which is stored in location 4 * <interrupt
type>. Interrupt processing routine should return with the IRET instruction.
(ii) Software Interrupts (Internal Interrupts and Instructions) .Software interrupts can be
caused by:
INT instruction - breakpoint interrupt. This is a type 3 interrupt.
INT <interrupt number> instruction - any one interrupt from available 256 interrupts.
Single-step interrupt - generated if the TF flag is set. This is a type 1 interrupt. When
the CPU processes this interrupt it clears TF flag before calling the interrupt
processing routine.
Processor exceptions: Divide Error (Type 0), Unused Opcode (type 6) and Escape
opcode (type 7).
ISR is responsible for displaying the message “Divide Error” on the screen
INT 01
When ever NMI pin of the 8086 is activated by a high signal (5v), the CPU Jumps
to physical memory location 00008 to fetch CS:IP of the ISR associated with NMI.
A break point is used to examine the CPU and memory after the execution of a group
of Instructions.
It is one byte instruction whereas other instructions of the form “INT nn” are 2
byte instructions.
If INT 0 is placed after a signed number arithmetic as IMUL or ADD the CPU
will activate INT 04 if 0F = 1.
In case where 0F = 0, the INT 0 is not executed but is bypassed and acts as a NOP.
AD0-AD15 (Bidirectional)
Address/Data bus
20 Address lines denoted as AD0-AD15 and
A16/S3, A17/S4, A18/S5, A19/S6. 16 Data Lines are
AD0-AD15.
MN/ MX
MINIMUM / MAXIMUM
3
8086 Microprocessor Pins and Signals Common signals
READY
1-No effect on microprocessor operation
0-8086 enters in to wait state like idle
state, to synchronize with slow
peripheral devices
RESET (Input)
CLK
The clock input provides the basic timing for
processor operation and bus control activity.
NMI-Non-Maskable Interrupt
It is a edge triggered and is type-2 interrupt
5
8086 Microprocessor Pins and Signals Min/ Max Pins
6
8086 Microprocessor Pins and Signals Minimum mode signals
(Data Enable) Output signal from the processor used as out put
enable for the transceivers
7
8086 Microprocessor Pins and Signals Minimum mode signals
9
8086 Microprocessor Pins and Signals Maximum mode signals
10
8086 Microprocessor Pins and Signals Maximum mode signals
The output on QS0 and QS1 can be interpreted as shown in the table.
11
8086 Microprocessor Memory organization in 8086
12
8086 Microprocessor Memory organization in 8086
Operation A0 Data Lines Used
13
Stack Structure of 8086 Microprocessor