K.Praveen Kumar: Asst. Professor GITAM University
K.Praveen Kumar: Asst. Professor GITAM University
K.Praveen Kumar: Asst. Professor GITAM University
Praveen Kumar
Asst. Professor
GITAM University
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
Data Transfer Instructions
Arithmetic Instructions
Logical Instructions
Program Control Transfer or Branching
Instructions
String Instructions
Processor Control Instructions
3
Data Transfer
Instructions
These instructions are used to
transfer data from source to
destination.
The operand can be a constant,
memory location, register or I/O port
address.
4
Data Transfer
Instructions
MOV Des, Src:
Src operand can be register, memory location or
immediate operand.
Des can be register or memory operand.
5
Data Transfer
Instructions
PUSH Operand:
It pushes the operand into top of stack.
POP Des:
It pops the operand from top of stack to Des.
6
Data Transfer
Instructions
XCHG Des, Src:
This instruction exchanges Src with Des.
7
Data Transfer
Instructions
IN Accumulator, Port Address:
It transfers the operand from specified port to
accumulator register.
E.g.: IN AX, 0028 H
E.g.: IN AL, 28 H
E.g.: IN AL, DX
E.g.: IN AX, DX
8
OUT Port Address, Accumulator:
It transfers the operand from accumulator to specified
port.
E.g.: OUT DX, AX
9
Data Transfer
Instructions
LDS Des, Src:
It loads 32-bit pointer from memory source to
destination register and DS.
The offset is placed in the destination register
and the segment is placed in DS.
To use this instruction the word at the lower
memory address must contain the offset and the
word at the higher address must contain the
segment.
E.g.: LDS BX, [DI]
10
Data Transfer
Instructions
LES Des, Src:
It loads 32-bit pointer from memory source to
destination register and ES.
The offset is placed in the destination register
and the segment is placed in ES.
This instruction is very similar to LDS except
that it initializes ES instead of DS.
E.g.: LES DI, [BX]
11
Data Transfer
Instructions
LEA Register, Src:
It loads a 16-bit register with the
offset address of the data specified
by the Src.
E.g.: LEA BX, [DI]
This instruction loads the contents of DI
(offset) into the BX register.
12
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.
POPF:
Pops the stack top to flag register.
13
Data Transfer
Instructions
XLAT: Translate Byte to AL
14
Arithmetic
Instructions
ADD Des, Src:
It adds a byte to byte or a word to word.
E.g.:
ADD AL, 74H
ADD DX, AX
ADD AX, [BX]
15
Arithmetic
Instructions
ADC Des, Src:
It adds the two operands with CF.
E.g.:
ADC AL, 74H
ADC DX, AX
ADC AX, [BX]
16
Arithmetic
Instructions
SUB Des, Src:
It subtracts a byte from byte or a word from
word.
It effects AF, CF, OF, PF, SF, ZF flags.
E.g.:
SUB AL, 74H
SUB DX, AX
SUB AX, [BX]
17
Arithmetic
Instructions
SBB Des, Src:
It subtracts the two operands and also
the borrow from the result.
It effects AF, CF, OF, PF, SF, ZF flags.
E.g.:
SBB AL, 74H
SBB DX, AX
SBB AX, [BX]
18
Arithmetic
Instructions
INC Src:
It increments the byte or word by one.
CF is not effected.
E.g.: INC AX
19
Arithmetic
Instructions
DEC Src:
It decrements the byte or word by one.
CF is not effected.
E.g.: DEC AX
20
Arithmetic
Instructions
NEG Src:
It creates 2s complement of a
given number.
That means, it changes the sign of
a number.
21
Arithmetic
Instructions
CMP Des, Src:
It compares two specified bytes or words.
22
Arithmetic
Instructions
MUL Src:
It is an unsigned multiplication instruction.
DX : AX = AX * Src
IMUL Src:
It is a signed multiplication instruction.
23
Arithmetic
Instructions
DIV Src:
It is an unsigned division instruction.
24
Arithmetic
Instructions
CBW (Convert Byte to Word):
This instruction converts byte in AL to word in AX.
25
Representation of
Numbers
ASCII representation
Numbers are stored as a string of ASCII characters
Example: 1234 is stored as 31 32 33 34H
ASCII for 1 is 31H, for 2 is 32H, etc.
BCD representation
Unpacked BCD
Example: 1234 is stored as 01 02 03 04H
Additionalbyte is used for sign
Sign byte: 00H for + and 80H for
Packed BCD
Saves space by packing two digits into a byte
Example: 1234 is stored as 12 34H
26
Arithmetic
Instructions
DAA (Decimal Adjust after Addition)
It is used to make sure that the result of adding two
BCD numbers is adjusted to be a correct BCD
number.
It only works on AL register.
27
Processing Packed BCD
Numbers
Packed BCD addition
Example 1 Example 2
29H = 00101001B 27H = 00100111B
69H = 01101001B 34H = 00110100B
92H = 10010010B 5BH = 01011101B
Should be 98H (add 6) Should be 61H (add 6)
Example 3
52H = 01010010B
61H = 01100001B
B3H = 10110010B Should be 13H (add 60H)
28
Processing Packed BCD
Numbers
The daa instruction works as follows:
If the least significant four bits in AL are > 9 or
if AF =1, it adds 6 to AL and sets AF
If the most significant four bits in AL are > 9 or
if CF =1, it adds 60H to AL and sets CF
Example:
mov AL,71H
add AL,43H ; AL = B4H
daa ; AL = 14H and CF = 1
The result including the carry (i.e., 114H) is the
correct answer
29
Processing Packed BCD
Numbers
Packed BCD subtraction
The das instruction works as follows:
If the least significant four bits in AL are > 9 or
if AF =1, it subtracts 6 from AL and sets AF
If the most significant four bits in AL are > 9 or
if CF =1, it subtracts 60H from AL and sets CF
Example:
mov AL,71H
sub AL,43H ; AL = 2EH
das ; AL = 28H
30
Representation of
Numbers
Numbers are in ASCII form
when received from keyboard
when sending to the display
Binary form is efficient to process numbers
internally
31
Arithmetic
Instructions
AAA (ASCII Adjust after Addition):
The data entered from the terminal is in ASCII format.
32
Processing ASCII
Numbers
ASCII addition
Example 1 Example 2
34H = 00110100B 36H = 00110110B
35H = 00110101B 37H = 00110111B
69H = 01101001B 6DH = 01101101B
Should be 09H Should be 13H
Ignore 6 Ignore 6 and add 6 to D
The aaa instruction performs these
adjustments to the byte in AL register
33
Processing ASCII
Numbers
The aaa instruction works as follows:
If the least significant four bits in AL are > 9 or
if AF =1, it adds 6 to AL and 1 to AH.
Both CF and AF are set
In all cases, the most significant four bits in AL
are cleared
Example:
sub AH,AH ; clear AH
mov AL,36' ; AL = 36H
add AL,37' ; AL = 36H+37H = 6DH
aaa ; AX = 0103H
or AL,30H ; AL = 33H
34
Processing ASCII
Numbers
ASCII subtraction
The aas instruction works as follows:
If the least significant four bits in AL are > 9 or
if AF =1, it subtracts 6 from AL and 1 from AH.
Both CF and AF are set
In all cases, the most significant four bits in AL
are cleared
This adjustment is needed only if the result is
negative
35
Processing ASCII
Numbers
Example 1:
sub AH,AH ; clear AH
mov AL,39' ; AL = 39H
sub AL,33' ; AL = 39H-33H = 6H
aas ; AX = 0006H
or AL,30H ; AL = 36H
36
Processing ASCII
Numbers
ASCII multiplication
The aam instruction adjusts the result of a mul
instruction
Multiplication should not be performed on ASCII
Can be done on unpacked BCD
The aam instruction works as follows
AL is divided by 10
Quotient is stored in AH
Remainder in AL
aam does not work with imul instruction
37
Processing ASCII
Numbers
Example 1
mov AL,03 ; multiplier in unpacked BCD form
mov BL,09 ; multiplicand in unpacked BCD form
mul BL ; result 001BH is in AX
aam ; AX = 0207H
or AX,3030H ; AX = 3237H
Example 2
mov AL,33' ; multiplier in ASCII
mov BL,39' ; multiplicand in ASCII
and AL,0FH ; multiplier in unpacked BCD form
and BL,0FH ; multiplicand in unpacked BCD form
mul BL ; result 001BH is in AX
aam ; AX = 0207H
or AL,30H ; AL = 37H
38
Processing ASCII
Numbers
ASCII division
The aad instruction adjusts the numerator in AX
before dividing two unpacked decimal numbers
The denominator is a single unpacked byte
The aad instruction works as follows
Multiplies AH by 10 and adds it to AL and sets AH to
0
Example:
If AX is 0207H before aad
AX is changed to 001BH after aad
40
Logical Instructions
These instructions are used at the bit level.
41
Logical Instructions
NOT : Logical Invert Src
It complements each bit of Src to produce 1s
complement of the specified operand.
The operand can be a register or memory
location.
Ex: NOT AX
42
Logical Instructions
AND: Logical AND Des, Src:
It performs AND operation of Des and Src.
43
Logical Instructions
OR: Logical OR Des, Src:
It performs OR operation of Des and Src.
44
Logical Instructions
XOR: Logical Exclusive OR Des, Src:
It performs XOR operation of Des and Src.
45
Logical Instructions
SHL/SAL: Shift Logical/Arithmetic Left Des,
Count:
It shift bits of byte or word left, by count.
46
Logical Instructions
SHR: Shift Logical right Des, Count:
It shift bits of byte or word right, by count.
48
Logical Instructions
ROL: Rotate Left Without Carry Des, Count:
It rotates bits of byte or word left, by count.
49
Logical Instructions
ROR: Rotate Right Without Carry Des, Count:
It rotates bits of byte or word right, by count.
50
Logical Instructions
RCL: Rotate Left Through Carry Des, Count:
It rotates bits of byte or word left, by count.
51
Logical Instructions
RCR: Rotate Right Through Carry Des, Count:
It rotates bits of byte or word right, by count.
52
Branching Instructions
These instructions cause change in the
sequence of the execution of instruction.
This change can be through a condition or
sometimes unconditional.
The conditions are represented by flags.
53
Branching 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.
54
Branching Instructions
JMP Des:
This instruction is used for unconditional jump
from one place to another.
55
Conditional Jump Table
Mnemoni Meaning Jump
c Condition
JA Jump if Above CF = 0 and ZF
=0
JAE Jump if Above or Equal CF = 0
JB Jump if Below CF = 1
JBE Jump if Below or Equal CF = 1 or ZF =
1
JC Jump if Carry CF = 1
JE Jump if Equal ZF = 1
JNC Jump if Not Carry CF = 0
JNE Jump if Not Equal ZF = 0
JNZ Jump if Not Zero ZF = 0
JPE Jump if Parity Even PF = 1
56
JPO Jump if Parity Odd PF = 0
Branching Instructions
Loop Des:
This is a looping instruction.
57
String Instructions
String in assembly language is just a
sequentially stored bytes or words.
There are very strong set of string instructions
in 8086.
By using these string instructions, the size of
the program is considerably reduced.
58
String Instructions
MOVS / MOVSB / MOVSW:
It causes moving of byte or word from one
string to another.
In this instruction, the source string is in Data
Segment and destination string is in Extra
Segment.
SI and DI store the offset values for source and
destination index.
59
String Instructions
REP/ REPE/ REPNE/ REPZ/ REPNZ
(Repeat):
This is an instruction prefix.
60
String Instructions
CMPS/ CMPSB/ CMPSW Des, Src:
It compares the string bytes or words.
61
String Instructions
LODS/LODSB/LODSW Des, Src:
It loads the AL/AX register by the content of a
string pointed by DS:SI register pair.
62
ASCII Table:
63
Processor Control
Instructions
These instructions control the processor itself.
64
Processor Control
Instructions
STC:
It sets the carry flag to 1.
CLC:
It clears the carry flag to 0.
CMC:
It complements the carry flag.
STI:
It sets the interrupt flag to 1.
CLI:
It clears the interrupt flag to 0.
65
Processor Control
Instructions
STD:
It sets the direction flag to 1.
CLD:
It clears the direction flag to 0.
66
67