Unit-4 Co
Unit-4 Co
8086 Microprocessor
Contents
1. Architecture of 8086 Microprocessor
2. Special functions of General Purpose
Registers
3. 8086 Flag register
4. Function of 8086 Flags
5. Addressing modes of 8086
6. Instruction set of 8086
What is microprocessor ?
• A microprocessor is a computer processor that incorporates the functions
of a computer's central processing unit (CPU) on a single integrated circuit
(IC).
• The microprocessor is a multipurpose, programmable device that accepts
digital data as input, processes it according to instructions stored in its
memory, and provides results as output.
Generation of Microprocessor
• 1st Generation: This was the period during 1971 to 1973 of
microprocessor’s history. In 1971, INTEL created the first microprocessor
4004 that would run at a clock speed of 108 KHz.
• 2nd Generation: This was the period during 1973 to 1978 in which very
efficient 8-bit microprocessors -INTEL-8085.
• 3rd Generation: From 1979 to 1980, INTEL 8086/80186/80286 were
developed. It is 16-bit processor. Speeds of those processors were four
times better than the 2nd generation processors.
• 4th Generation: After 1980, INTEL 80386 & 80486 were developed. It is
32-bit processor
Terms related to Microprocessors
• Bit
Source SI
Index Registers
Destination DI
Base BP
Stack SP Pointer Regsiters
Instruction IP
SF Status Flags
Code CS
Data DS
Segment Registers
Extra ES
Stack SS
General Purpose Registers
• In 8086 there are 4- general purpose registers i.e., AX,BX,CX,DX.
• These registers are of 16-bit size and can be used either as a whole
16-bit register ( the letter X used in the representation of the register
indicates that the complete 16 – bit register is being used) or the
upper and lower bytes can be accessed separately ( the letters H and
L indicates the higher order and lower order bytes respectively in the
representation of the registers )
• The general purpose registers can be used to store both operands
and temporary results and each of them can be accessed as whole or
as sub-registers.
General Purpose Register
• In addition to serving as general purpose registers AX, BX, CX, DX
have special uses as addressing, counting, and I/O roles.
• The special uses of the general purpose registers is:
AX used as accumulator
• The flag register contents indicate the result of computation in the ALU.
It is also known as PSW ( Program Status Word).
• The flag register/PSW can be divided into 2-parts:
6- conditional flags
3- control flags
4. Function of 8086 Flags
Conditional flags: The lower byte of the flag register along with overflow flag,
they reflect the status of program.
Control Flags : Higher byte of the flag register , It has 3-flags i.e., direction
flag, interrupt flag and trap flag.
They control the working of machine(microprocessor)
BIT 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
X X X X O D I T S Z X AC X P X C
O Overflow flag, D Direction flag, I Interrupt flag,
T Trap flag, S Sign flag, Z Zero flag,
AC Auxiliary Carry flag, P Parity flag
CY Carry flag, X Not used / Undefined
Control flags
2. Arithmetic instructions
4. String instructions
instruction set 39
Data transfer instructions
• MOV: Copy byte or word from specified source to
specified destination.
Format: MOV <dest>, <source>
Operation: (dest) (source)
Examples: 1.MOV AX,5000H
2.MOV AX,BX
3. MOV AX,[2000H]
4.MOV AX,[SI]
5. MOV AX,50H[BX]
Data transfer instructions
instruction set 41
Data transfer instructions
Examples: 1.POP AX
2.POP [5000H]
instruction set 42
Data transfer instruction
instruction set 43
Data transfer instructions
instruction set 44
Data transfer instructions
• OUT : Writing data to an output port from
accumulator.
Format : OUT <Destination>, AL/AX
(port) AL/AX
Example:
OUT 03H,AL ;sends the data available in AL to
port whose address is 03h.
OUT DX,AX ; sends the data available in AX to
port whose address is specified in DX.
instruction set 45
Data transfer instructions
• XLAT: Translate a byte in AL, using a table in
memory
Format: XLAT
instruction set 46
Data transfer instructions
instruction set 47
Data transfer instructions
• LDS : Load DS register and the other specified register
from memory.
Format: LDS Reg16,Mem
(Reg16) (Mem)
(DS) (Mem+2)
Example: LDS BX,5000H
instruction set 48
Data transfer instructions
instruction set 49
Data transfer instructions
• PUSHF: Push the flag register to the stack.
(sp) (sp)-2
the stack pointer is decremented by two for each
push operation.
instruction set 50
Arithmetic instructions
1. ADD 10. IMUL 15.AAA
11. CBW
16.AAS
12. CBD
13.DIV 17.AAM
2. ADC
14.IDIV 18.AAD
3. INC
4. DEC 19.DAA
5. SUB 20.DAS
6. SBB
7. CMP
8. NEG
9. MUL
Arithmetic instructions
1. ADD: Adds the contents of two registers or a immediate data to
register or contents of one memory location to a register contents
are added.
The ADD instruction affects all conditional flags depending on the result
of operation.
Example: ADD AX,BX
ADD AX,0100H
ADD AX,[5000H]
2. ADC: Add with carry
Add the carry bit to the result.
Ex: ADC AX,BX
ADC AX,[5000H]
Arithmetic instructions
3. INC: Increment
Increases the contents of register or memory location by 1
Ex: INC AX
INC [5000H]
4. DEC: Decrement
Ex: DEC AX
DEC [5000H]
Arithmetic instructions
5. SUB: Subtract
• This instruction subtracts the source operand from the destination
operand and the result is stored in destination.
• The source operand may be a register or a memory location or an
immediate data and the destination operand may be a register or a
memory location.
• All the conditional flags are affected by SUB instruction.
Example: SUB AX,BX
SUB AX,1000H
SUB AX,[5000H]
6. SBB: Subtract with borrow
Subtract 1 from subtraction obtained by SUB.
Ex: SBB AX,BX
SBB AX,[5000H]
Arithmetic instructions
7.CMP :Compare
NEG Mem./Reg.
The negate instruction forms 2’s complement of the specified
destination in the instruction.
For obtaining 2’s complement,it subtracts the contents of
destination from 0(zero).
The result is stored back in the destination operand which may be
a register or a memory location.
Using NEG instruction if the OF flag is set, it will indicate that the
operation was not successfully completed.
The NEG instruction affects all conditional flags.
Example: NEG BX
56
Arithmetic instructions
9. MUL : Multiplication
Example: MUL BL
MUL BX
ARITHMETIC INSTRUNCTIONS
Example: IMUL BL
IMUL BX
58
ARITHMETIC INSTRUCTIONS
EX:
1. If AL = 1000 0000(80h)
Then AH 1111 1111(FFh)
AX=FF80H
59
Arithmetic instructions
12. CWD : Convert signed word to double word
CWD instruction copies the sign bit of AX to all the bits
of DX register
This operation is to be done before signed division.
Bit-15 of AX is moved to all the bits of DX register.
EX:
1. If AX = 1000 0000 0000 0000(8000H)
then DX 1111 1111 1111 1111 (FFFFH)
Arithmetic instructions
13. DIV : division
DIV <reg./Mem>
It divides an word or double word by a 16-bit or 8-bit
operand.
The dividend for 32-bit operation will be in DX:AX
register pair (Most significant word in DX and least
significant word in AX).
The result of division is for 16-bit number divided by 8-
bit number the Quotient will be in AL register and the
remainder will be in AH register similarly for 32-bit
number divided by 16-bit number the Quotient will be
in AX register and the remainder will be in DX register.
EX: DIV BL
DIV BX
61
ARITHMETIC INSTRUCTIONS
14. IDIV : signed division
IDIV <reg./Mem>
This instruction performs signed division. It divides an signed word or
double word by a signed 16-bit or 8-bit operand.
While using IDIV instruction the contents of accumulator and register
should be sign extended binary.
The signed dividend for 32-bit operation will be in DX:AX register pair
(Most significant word in DX and least significant word in AX).
All the flags are undefined for IDIV instruction.
The sign of the quotient depends on the sign of dividend and divisor. The
sign of remainder will be same as that of dividend.
The result of division of signed division is also stored in the same way as
the result of unsigned division but the sign of the quotient and remainder
depends on the sign of dividend and divisor.
EX: IDIV BL
IDIV BX
62
ARITHMETIC INSTRUCTIONS
15. AAA : ASCII Adjust after Addition
The AAA instruction is executed after an ADD instruction that adds two ASCII
coded operands to give a byte of result in AL. The AAA instruction converts
the resulting contents of AL to unpacked decimal digits.
After the addition the AAA instruction examines the lower 4-bits of AL to
check whether it contains a valid BCD between 0 to 9.
64
16. AAS : ASCII adjust AL after subtraction
As a result, the upper nibble of AL is 00 and the lower nibble may be any
number from 0 to 9.
instruction.
EX:
MOV AL, 04 ; AL 04
MOV BL, 09 ; BL 09
MUL BL ; AH:AL 24 H (9 X 4)
AAM ; AH 03
AL 06
18. AAD: ASCII adjust before division
The AAD instruction converts two unpacked BCD digits in AH and AL to
the equivalent binary in AL.
The ASCII adjustment must be made before dividing the two unpacked BCD
digits in AX by an unpacked BCD byte.
The AAD instruction has to be used before DIV instruction is used in the
program.
Example: Divide 27 by 5
aad ; AX := 001BH
div BL ; AX := 0205H
19. DAA : Decimal adjust Accumulator
Example: AL = 53, CL = 29
AL = 53 + 29 = 7C H
AL = 82
ARITHMETIC INSTRUCTIONS
20.DAS: Decimal adjust after subtraction
DAS
The instruction converts the result of subtraction of two packed BCD numbers
to a valid BCD number.
If the lower nibble of AL is greater than 9, this instruction will subtract06 from
the lower nibble of AL. If the result of subtraction sets the carry flag or if
upper nibble is greater than 9, it subtracts 60 H from AL.
DAA and DAS instructions are also called packed BCD arithmetic instructions.
69
ARITHMETIC INSTRUCTIONS
Example:
• (1) AL = 75, BL = 46
SUB AL,BL ; AL 2F = (AL) – (BL)
; AF = 1
DAS ; AL 29 ( as F > 9, F-6 = 9)
(2) AL = 38 , DL = 61
SUB AL , DL ; AL D7 & CF = 1(borrow)
DAS ; AL 77 (as D > 9 , D-6 = 7)
; CF = 1 (borrow)
70
LOGICAL INSTRUCTIONS
1. AND 6. SHL/SAL 9. ROR
2. OR 7. SHR 10.ROL
3. NOT 8. SAR 11.RCR
4. XOR 12.RCL
5. TEST
LOGICAL INSTRUCTIONS
76
LOGICAL INSTRUCTIONS
CF MSB 0
These instructions shift the operand word or byte bit by bit to the left
and insert zeros in the newly introduced least significant bits.
The number of bits to be shifted if 1 will be specified in the
instruction itself if the count is more than 1 then the count will be in
CL register.
The operand to be shifted can be either register or memory location
contents but cannot be immediate data.
77
LOGICAL INSTRUCTIONS
0 MSD LSD CF
These instructions shift the operand word or byte bit by bit to the
right and insert zeros in the newly introduced Most significant bits.
The result of the shift operation will be stored in the register itself.
The number of bits to be shifted if 1 will be specified in the
instruction itself if the count is more than 1 then the count will be in
CL register.
The operand to be shifted can be either register or memory location
contents but cannot be immediate data.
78
LOGICAL INSTRUCTIONS
MSB LSB CF
These instructions shift the operand word or byte bit by bit to the
right.
SAR instruction inserts the most significant bit of the operand in the
newly inserted bit positions.
The result will be stored in the register or memory itself.
The number of bits to be shifted if 1 will be specified in the
instruction itself if the count is more than 1 then the count will be in
CL register.
The operand to be shifted can be either register or memory location
contents but cannot be immediate data.
79
LOGICAL INSTRUCTIONS
CF
This instruction rotates all the bits in a specified word or byte to the left by
the specified count (bit-wise) excluding carry.
The MSB is pushed into the carry flag as well as into LSB at each operation.
The remaining bits are shifted left subsequently by the specified count
positions.
The operand can be a register or a memory location.
The count will be represented with CL register.
80
LOGICAL INSTRUCTIONS
CF
This instruction rotates all the bits in a specified word or byte to the left by
the specified count (bit-wise) including carry.
The MSB is pushed into the CF and CF into LSB at each operation. The
remaining bits are shifted left subsequently by the specified count positions.
The operand can be a register or a memory location.
81
LOGICAL INSTRUCTIONS
CF
This instruction rotates all the bits in a specified word or byte to the right by
the specified count (bit-wise) excluding carry.
The LSB is pushed into the carry flag as well as the MSB at each operation.
The remaining bits are shifted right subsequently by the specified count
positions.
82
LOGICAL INSTRUCTIONS
CF
This instruction rotates all the bits in a specified word or byte to the right by
the specified count (bit-wise) excluding carry.
The LSB is pushed into the carry flag as well as the MSB at each operation.
The remaining bits are shifted right subsequently by the specified count
positions.
The operand can be a register or a memory location.
83
String Instructions
A string is a sequence of bytes or words i.e., a series of data bytes or words
available in memory at consecutive locations, to be referred to collectively or
individually and is known as byte strings or word strings.
For referring to a string, two parameters are required,
In the case of 8086, index registers are used as pointers for the source and
destination strings (SI and DI respectively). The pointers are updated i.e.,
incrementing and decrementing of the pointers depending on the status of the DF
flag.
84
String Instructions
The string instructions are categorized as
1. Prefix instructions
The instruction with REP prefix will be executed repeatedly until the CX
register becomes zero ( for each iteration CX is automatically decremented
by one).
86
String Instructions
String data byte/word manipulation instructions
MOVS / MOVSB / MOVSW: Move string byte or word
Moves a string of bytes stored in one set of memory location to another set
of memory locations
The SI register points to the source string in the DS and DI register points
to the destination string in the ES.
REP prefix is used with MOVS instruction to repeat it by a value given in
CX register.
The CX register is decremented by one for each byte / word movement.
The SI and DI registers are automatically incremented or decremented
depending on the status of DF.
87
String Instructions
String data byte/word manipulation instructions
Compare one byte or word of a string data stored in data segment with that
stored in extra segment.
The SI register points to the source string and DI register points to the
destination string.
89
String Instructions
String data byte/word manipulation instructions
LODS / LODSB / LODSW: Load string byte or word into AL register.
One byte or word of a string data stored in data segment is loaded into
AL / AX register.
90
String Instructions
String data byte/word manipulation instructions
91
Flag manipulation & Processor Control
Instructions
The flag manipulation instructions directly modify some of the flags of
the 8086 flag register.
The machine control instructions controls the bus usage and execution.
The Various Flag manipulation instructions are
92
Flag manipulation Instructions
CLC : Clear Carry
The carry flag is reset to zero i.e., CF = 0
CF 0
CMC : Complement the carry
The carry Flag is Complemented i.e., if CF = 0 before CMC then after
CMC CF =1 and vice versa.
CF ~ CF
STC : Set Carry
The carry flag is set to one i.e., CF = 1
CF 1
CLD : Clear direction
The direction flag is cleared to zero i.e., DF = 0
DF 0
STD : Set direction
The direction flag is set to 1 i.e., DF = 1
DF 1
93
Flag manipulation instructions
IF 0
STI : Set Interrupt
IF 1
94
Processor Control Instructions
• WAIT: wait for a TEST input pin to go low
The WAIT instruction when executed, holds the processor until TEST input
pin goes low.
• HLT: Halt the processor
The HLT instruction will cause the 8086 to stop the fetching and execution
of the instructions. The 8086 will enter a halt state i.e., used to terminate a
program.
• NOP: No operation
ESC instruction when executed, frees the bus for peripheral devices.
• LOCK: Bus lock instruction prefix
• CALL
• RET
• INT N
• INTO
• JMP
• IRET
• LOOP
Unconditional branch instructions
• CALL: Unconditional call
• This instruction executes the part of program from the label to loop
instruction by cx no.of times at each iteration, cx is decremented
automatically.
EX: mov cx,0005h
mov ax,0001
label: mov bx,0002h
Or ax,bx
loop label
Conditional branch instructions
S.No Mnemonic Condition Operation by instruction
.
1. JA / JNBE CF = 0 AND ZF =0 Jump if above / Jump if not below
or equal.
2. JAE / JNB CF =0 Jump if above or equal / Jump if
not below
3. JB /JNAE CF = 1 Jump if below / Jump if not above
or equal
4. JC CF = 1 Jump if carry flag (CF) = 1.
5. JNC CF = 0 Jump if no carry i.e., CF = 0
6. JE /JZ ZF =1 Jump if equal / Jump if zero ( ZF =
1)
7. JNE / JNZ ZF = 0 Jump if not equal/ Jump if Non
zero (ZF = 0)
103
Conditional branch instructions
104
Conditional branch instructions
105