K.Praveen Kumar: Asst. Professor GITAM University

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 67

K.

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.

Both Src and Des cannot be memory location at


the same time.
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.

The operand can be a general purpose register or segment


registers or memory location.
E.g.: PUSH BX

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

6
Data Transfer
Instructions
XCHG Des, Src:
This instruction exchanges Src with Des.

It cannot exchange two memory locations directly.

E.g.: XCHG DX, AX

E.g.: XCHG DX, [SI]

E.g.: XCHG [DI], AX

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

E.g.: OUT 32H, AL

E.g.: OUT DX, AL

E.g.: OUT 0028 H, AX

E.g.: OUT 45H, AL

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

The translate instruction is used for finding out


the codes in case of code conversion problems,
using look up table technique.

14
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.

E.g.:
ADD AL, 74H
ADD DX, AX
ADD AX, [BX]

15
Arithmetic
Instructions
ADC Des, Src:
It adds the two operands with CF.

It effects AF, CF, OF, PF, SF, ZF flags.

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.

For subtraction, CF acts as borrow flag.

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.

The operand can be a register or


memory location.
It effects AF, OF, PF, SF, ZF flags.

CF is not effected.

E.g.: INC AX

19
Arithmetic
Instructions
DEC Src:
It decrements the byte or word by one.

The operand can be a register or


memory location.
It effects AF, OF, PF, SF, ZF flags.

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.

The Src and Des can be a constant, register or


memory location.
Both operands cannot be a memory location at
the same time.
The comparison is done simply by internally
subtracting the source from destination.
The value of source and destination does not
change, but the flags are modified to indicate the
result.

22
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

This instruction assumes one of the operand in AL or AX.

Src can be a register or memory location.

IMUL Src:
It is a signed multiplication instruction.

23
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
IDIV Src:
It is a signed division instruction.

24
Arithmetic
Instructions
CBW (Convert Byte to Word):
This instruction converts byte in AL to word in AX.

The conversion is done by extending the sign bit


of AL throughout AH.
CWD (Convert Word to Double Word):
This instruction converts word in AX to double
word in DX : AX.
The conversion is done by extending the sign bit
of AX throughout DX.

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.

DAS (Decimal Adjust after Subtraction)


It is used to make sure that the result of subtracting
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.

In ASCII, 0 9 are represented by 30H 39H.

This instruction allows us to add the ASCII codes.

This instruction does not have any operand.

Other ASCII Instructions:


AAS (ASCII Adjust after Subtraction)

AAM (ASCII Adjust after Multiplication)

AAD (ASCII Adjust Before Division)

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

aad instruction reverses the changes done by aam


39
Processing ASCII
Numbers
Example: Divide 27 by 5

mov AX,0207H ; dividend in unpacked BCD form


mov BL,05H ; divisor in unpacked BCD form
aad ; AX = 001BH
div BL ; AX = 0205H
aad converts the unpacked BCD number in AX
to binary form so that div can be used

40
Logical Instructions
These instructions are used at the bit level.

These instructions can be used for:


Testing a zero bit

Set or reset a bit

Shift bits across registers

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.

Src can be immediate number, register or memory


location.
Des can be register or memory location.

Both operands cannot be memory locations at the same


time.
CF and OF become zero after the operation.

PF, SF and ZF are updated.

Ex: AND AL, OFH

43
Logical Instructions
OR: Logical OR Des, Src:
It performs OR operation of Des and Src.

Src can be immediate number, register or memory


location.
Des can be register or memory location.

Both operands cannot be memory locations at the same


time.
CF and OF become zero after the operation.

PF, SF and ZF are updated.

Ex: OR AL, OFH

44
Logical Instructions
XOR: Logical Exclusive OR Des, Src:
It performs XOR operation of Des and Src.

Src can be immediate number, register or


memory location.
Des can be register or memory location.

Both operands cannot be memory locations at


the same time.
CF and OF become zero after the operation.

PF, SF and ZF are updated.

45
Logical Instructions
SHL/SAL: Shift Logical/Arithmetic Left Des,
Count:
It shift bits of byte or word left, by count.

It puts zero(s) in LSBs.

MSB is shifted into carry flag.

If the number of bits desired to be shifted is 1, then


the immediate number 1 can be written in Count.
However, if the number of bits to be shifted is more
than 1, then the count is put in CL register.

46
Logical Instructions
SHR: Shift Logical right Des, Count:
It shift bits of byte or word right, by count.

It puts zero(s) in MSBs.

LSB is shifted into carry flag.

If the number of bits desired to be shifted is 1,


then the immediate number 1 can be written in
Count.
However, if the number of bits to be shifted is
more than 1, then the count is put in CL register.
47
Logical Instructions
SAR: Shift arithmetic Right Des, Count:
It shift bits of byte or word right, by count.

It puts the most significant bit of the operand in


newly inserted positions..
LSB is shifted into carry flag.

If the number of bits desired to be shifted is 1, then


the immediate number 1 can be written in Count.
However, if the number of bits to be shifted is more
than 1, then the count is put in CL register.

48
Logical Instructions
ROL: Rotate Left Without Carry Des, Count:
It rotates bits of byte or word left, by count.

MSB is transferred to LSB and also to CF.

If the number of bits desired to be shifted is 1, then


the immediate number 1 can be written in Count.
However, if the number of bits to be shifted is more
than 1, then the count is put in CL register.
Ex 1: ROL CX, 1 EX 2: MOV CL,03
ROL BL,CL

49
Logical Instructions
ROR: Rotate Right Without Carry Des, Count:
It rotates bits of byte or word right, by count.

LSB is transferred to MSB and also to CF.

If the number of bits desired to be shifted is 1, then the


immediate number 1 can be written in Count.
However, if the number of bits to be shifted is more than 1,
then the count is put in CL register.
Ex 1: ROR CX, 1 EX 2: MOV CL,03
ROR BL,CL

50
Logical Instructions
RCL: Rotate Left Through Carry Des, Count:
It rotates bits of byte or word left, by count.

MSB is transferred to CF and to LSB.

If the number of bits desired to be shifted is 1, then the


immediate number 1 can be written in Count.
However, if the number of bits to be shifted is more
than 1, then the count is put in CL register.
Ex 1: RCL CX, 1 EX 2: MOV CL,03
RCL BL,CL

51
Logical Instructions
RCR: Rotate Right Through Carry Des, Count:
It rotates bits of byte or word right, by count.

LSB is transferred to CF and to MSB.

If the number of bits desired to be shifted is 1, then the


immediate number 1 can be written in Count.
However, if the number of bits to be shifted is more
than 1, then the count is put in CL register.
Ex 1: RCR CX, 1 EX 2: MOV CL,03
RCR BL,CL

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.

Jxx Des (Conditional Jump):


All the conditional jumps follow some
conditional statements or any instruction that
affects the flag.

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.

The number of times looping is required is


placed in the CX register.
With each iteration, the contents of CX are
decremented.
ZF is checked whether to loop again or not.

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.

It causes the repetition of the instruction until


CX becomes zero.
E.g.: REP MOVSB STR1, STR2

It copies byte by byte contents.


REP repeats the operation MOVSB until CX becomes
zero.

60
String Instructions
CMPS/ CMPSB/ CMPSW Des, Src:
It compares the string bytes or words.

SCAS/ SCASB/ SCASW String:


It scans a string.

It compares the String with byte in AL or with


word in AX.

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.

STOS/STOSB/STOSW DES, Src:


It stores the AL/AX register contents to a
location in the string pointed by ES:DI register
pair.

62
ASCII Table:

63
Processor Control
Instructions
These instructions control the processor itself.

8086 allows to control certain control flags


that:
causes the processing in a certain direction

processor synchronization if more than one


microprocessor attached.

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.

If it is set, string bytes are accessed from higher


memory address to lower memory address.

CLD:
It clears the direction flag to 0.

If it is reset, the string bytes are accessed from


lower memory address to higher memory address.

66
67

You might also like