0% found this document useful (0 votes)
18 views

8086 Instruction Set

Uploaded by

rv93498
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

8086 Instruction Set

Uploaded by

rv93498
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60





INSTRUCTION SET
OF 8086
MICROPROCESSOR
8086 Instruction Set
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.
Classif ication of Instruction Set
Data Transfer Instructions
Arithmetic and Logical Instructions
String Instructions
Program Control transfer Instructions
Iteration control Instructions
Machine control and Miscellaneous
Instructions
Interrupt Instructions
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 por t address.
It can be classified as
MOV Instructions
PUSH/POP Instructions
Load Effective Address Instructions
String Data transfer Instructions
Miscellaneous Data transfer Instructions
MOV Instructions
Syntax
MOV Destination, Source
 Copies a word or a byte of data from source to destination.
 Source operand can be register, memory location or
immediate operand.
Destination can be register or memory operand.
Both Source and Destination cannot be memory location at
the same time.
E.g.:
MOV CX, 037A H
MOV AL, BL
• MOV BX, [3001 H]
PUSH/POP Instructions
PUSH

Syntax

PUSH Source

It pushes the operand into top of stack.

E.g.: PUSH BX

POP
Syntax
POP Destination

It pops the operand from top of stack to Des.

Destination can be a general purpose register, segment register (except CS)


or memor y location.

E.g.: POP AX
PUSHF:
Syntax

PUSHF Source

Pushes flag register to top of stack.

POPF:
Syntax
POPF Destination

Pops the stack top to flag register.



Load Effective Address
Instructions
Syntax
• LEA Register, Source
It loads a 16-bit register with the
offset address of the data specified
by the Source.
E.g.: LEA BX, [DI]
This instruction loads the contents of DI
(offset) into the BX register.
Syntax
LDS Register, Memory address of 1 word st

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, [3001 H]
Syntax
LES Register, Memory address of 1st word

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 BX, [3001 H]
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.
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.
REP (Repeat):
This is an instruction prefix.
It causes the repetition of the instruction until CX
becomes zero. (ie., CX=0)
E.g.: REP MOVSB STR1, STR2
It copies byte by byte contents.
REP repeats the operation MOVSB until CX becomes
zero.
REPE
Repeat if equal
Condition CX=0 or ZF=0
REPZ
Repeat if Zero
Condition CX=0 or ZF=0
REPNE
Repeat if not equal
Condition CX=0 or ZF=1
REPNZ
Repeat if not zero
Condition CX=0 or ZF=1
Loading a String
LODS
LODSB
LODSW
These instruction copies a byte from a
string location pointed by SI to AL or a word
from a string location pointed by SI to AX.
Storing a string
STOS
STOSB
STOSW
These instruction copies a byte from
AL to a memory location in the extra
segment or copies a word from AX to a
memory location in the extra segment
Comparing string
CMPS
CMPSB
CMPSW
These instructions are used to
compare a byte or word from one string to
another.
Miscellaneous Data transfer
Instructions
XCHG
Syntax
XCHG Destination, Source
This instruction exchanges Src with Des.
It cannot exchange two memory locations directly.
E.g.: XCHG DX, AX
XLAT
Translate byte in AL
This instruction replaces a byte in the AL
register with a byte from look up table in memory.
LAHF

It copies the lower byte of flag


register to AH.
SAHF
It copies the contents of AH to
lower byte of flag register.
IN
Syntax
IN Accumulator, Port Address:
It transfers the operand from specified port to accumulator register.
E.g.: IN AX, 0028 H

OUT
Syntax
OUT Port Address, Accumulator:
It transfers the operand from accumulator to specified port.
E.g.: OUT 0028 H, AX
Arithmetic Instructions
ADD
Syntax ADD Destination, Source
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 AX, DX
ADD AX, [BX]
ADC
Syntax
ADC Destination, Source
It adds the two operands with CF.
It effects AF, CF, OF, PF, SF, ZF flags.
E.g.:
ADC AL, 74H
ADC AX, DX
ADC AX, [BX]
SUB
Syntax
SUB Destination, Source
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 AX, DX
SUB AX, [BX]
SBB
Syntax
SBB Destination, Source
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 AX, DX
SBB AX, [BX]
MUL
Syntax
MUL Source
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 o ne of the o perand in AL or AX.acts as a source
If BL
Src can be a register or memo ry location. then the operation will be
Eg: MUL BX AL*BL and the O/P LSB
IMUL will be in AL and MSB will
Syntax be in AH
If BX acts as a source
IMUL Source
then the operation will be
It is a signed multiplication instruction.
AX*BX and the O/P LSB
will be in AX and the MSB
will be in DX
DIV
Syntax

DIV Source

It is a n unsigned division instruction.

It divides word by byte or double word by word.

The operand is stored in AX, divisor is Src a nd the result is stored as:

DX, AH = remainder AX, AL = quotient

Eg: DIV BX

IDIV

Syntax

IDIV Source

It is a signed division instruction.


INC
Syntax
INC Source
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
DEC
Syntax
DEC Source
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
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)
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.
NEG
Syntax
NEG Source
It creates 2’s complement of a given
number.
That means, it changes the sign of a
number.
Eg:
NEG AL
CMP
Syntax
CMP Destination, Source
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 th e same
• time.
The comparison is done simply by internally subtracting the
source from destination.
The value of source and destination does n ot change, but
• the flags are modified to indicate the result.
Logical Instructions
AND
Syntax
AND Destination, Source
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.
OR
Syntax
OR Destination, Source
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.
XOR
Syntax
XOR Destination, Source
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.
NOT
Syntax
NOT Source
It complements each bit of Src to produce 1’s
complement of the specified operand.
The operand can be a register or memory location.
Eg:
NOT AL
NOT CX
TEST
Syntax TEST Destination, Source
It is a special form of AND operations
the difference is that the AND Instructions
changes the destination operand while the
TEST instructions does not.
SHIFT AND ROTATE
INSTRUCTIONS
SHIFT Instructions
SAL/SHL
SHR
SAR
Syntax SAL – SAL Destination, Count
SHL – SHL Destination, Count

SAL and SHL are two mnemonics for the same instruction.
This instruction shifts each bit in the specified destination
some number of bit positions to the left. As a bit is shifted
out of the LSB operation, a 0 is put in the LSB position. The
MSB will be shifted into CF. In the case of multi-bit shift,
CF will contain the bit most recently shifted out from the
MSB. Bits shifted into CF previously will be lost.

CF MSB LSB 0
SHR
Syntax SHR Destination, Count
This instruction shifts each bit in the specified destination
some number of bit positions to the right. As a bit is
shifted out of the MSB position, a 0 is put in its place. The
bit shifted out of the LSB position goes to CF. In the case
of multi-bit shifts, CF will contain the bit most recently
shifted out from the LSB. Bits shifted into CF previously
will be lost.
0 MSB LSB CF
SAR
Syntax SAR Destination, Count

This instruction shifts each bit in the specified


destination some number of bit positions to the right.
As a bit is shifted out of the MSB position, a copy of
the old MSB is put in the MSB position. In other words,
the sign bit is copied into the MSB. The LSB will be
shifted into CF. In the case of multiple-bit shift, CF will
contain the bit most recently shifted out from the LSB.
Bits shifted into CF previously will be lost.

MSB MSB LSB CF


Rotate Instructions
RCL
Syntax RCL Destination, Count
This instruction rotates all the bits in a specified
word or byte some number of bit positions to the left. The
operation circular because the MSB of the operand is
rotated into the carry flag and the bit in the carry flag is
rotated around into LSB of the operand.
CF MSB LSB
RCR
Syntax RCR Destination, Count
This instruction rotates all the bits in a specified word or
byte some number of bit positions to the right. The
operation circular because the LSB of the operand is
rotated into the carry flag and the bit in the carry flag is
rotate around into MSB of the operand.

CF MSB LSB
ROL
Syntax ROL Destination, Count

This instruction rotates all the bits in a specified word or


byte to the left some number of bit positions. The data bit
rotated out of MSB is circled back into the LSB. It is also
copied into CF. In the case of multiple-bit rotate, CF will
contain a copy of the bit most recently moved out of the
MSB.

CF MSB LSB
ROR
Syntax ROR Destination, Count
This instruction rotates all the bits in a specified word or
byte some number of bit positions to right. The operation
is desired as a rotate rather than shift, because the bit
moved out of the LSB is rotated around into the MSB.
The data bit moved out of the LSB is also copied into CF.
In the case of multiple bit rotates, CF will contain a copy
of the bit most recently moved out of the LSB.
CF MSB LSB

Program Control transfer
Instructions
Control transfer Instructions are
Unconditional Jump
Conditional Jump
CALL Instructions
RET Instructions
Iteration Control Instructions
Unconditional Jump
JMP (UNCONDITIONAL JUMP TO
SPECIFIED DESTINATION)
Syntax
JMP CONTINUE
This instruction fetches the next
instruction from address at label CONTINUE.
Conditional Jump
Mnemonic Meaning Jump 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
JPO Jump if Parity Odd PF = 0
JZ Jump if Zero ZF = 1
CALL Instruction
Syntax
CALL Destination
This instruction is used to call a
subroutine or function or procedure.
The address of next instruction after CALL
is saved onto stack.
Eg: CALL CX
There are two types of CALL
Near CALL
Far CALL
A Near CALL is a call to a procedure
which is in the same code segment from
that which contains the CALL instruction.
A Far CALL is a call to a procedure
which is in the different code segment from
that which contains the CALL instruction.
RET Instruction
Syntax
RET
It returns the control from procedure to
calling program.
Every CALL instruction should have a
RET.
Iteration Control Instructions
LOOP
Syntax
LOOP Destination
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.
LOOPE/LOOPZ
Loop through a sequence of instruction
is equal or loop through a sequence of
instruction is zero.
here CX=0 ZF=0
LOOPNE/LOOPNZ
Loop through a sequence of
instruction is not equal or not zero
here CX=0 or ZF=1
Machine control and
Miscellaneous Instructions
STC:
It sets the carry flag to 1.

CLC:
It clears the carry flag to 0.

CMC:
It complements the carry flag.
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.
STI
Set the interrupt flag
CLI
Reset the interrupt flag
HLT
Stop the program or to stop fetching and
executing instruction
WAIT
When this instruction execute, 8086 enters
an ideal condition where it is doing no
processing
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.
NOP
No operation is performed
ESC
This instruction is used to pause the
instruction to a co-processor
LOCK
The lock prefix allows a microprocessor to
make sure that another processor does not
take the control of the system bus while it is in
the middle of a critical instructions which uses
the system bus
Interrupt Instructions
INT
Interrupts program
Syntax
INT – INT TYPE
The term type in the instruction format
refers
which to a number between 0 and 255,
identify the interrupt.
INTO
Interrupt overflow
It occurs when OF=1
IRET
Interrupt Return
Returns from interrupt service
procedure to main program

You might also like