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

8086 Instruction Set

The document describes the instruction set of the 8086 microprocessor. It includes data transfer instructions, arithmetic instructions, logical instructions, shift/rotate instructions, string manipulation instructions, branch/loop instructions, flag manipulation instructions, and machine control instructions. Specific instructions are discussed like MOV, PUSH, POP, IN, OUT, LEA, LDS, LES, LAHF, SAHF, PUSHF, and POPF. Examples demonstrate how various instructions work by showing the effect on registers and memory.

Uploaded by

asmit gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

8086 Instruction Set

The document describes the instruction set of the 8086 microprocessor. It includes data transfer instructions, arithmetic instructions, logical instructions, shift/rotate instructions, string manipulation instructions, branch/loop instructions, flag manipulation instructions, and machine control instructions. Specific instructions are discussed like MOV, PUSH, POP, IN, OUT, LEA, LDS, LES, LAHF, SAHF, PUSHF, and POPF. Examples demonstrate how various instructions work by showing the effect on registers and memory.

Uploaded by

asmit gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 50

8086 INSTRUCTION SET

6/3/21 1
8086 INSTRUCTION SET
1. Data Copy / Transfer Instructions
2. Arithmetic Instructions
3. Logical Instructions
4. Shift and Rotate Instructions
5. String Manipulation Instructions
6. Branch and Loop Instructions
5. Flag Manipulation Instructions
6. Machine Control Instructions

6/3/21 2
Instruction Set (continued...)
1. DATA TRANSFER INSTRUCTIONS
 Transfers data from one register or memory
location to another register or memory location

 Source: Seg.Register /
Gen.Register /Mem.location
 Destination: Seg.Register /
Gen.Register /Mem.location
 Note: Both Source and
Destination cannot be
Mem.Locn

6/3/21 3
Instruction Set (continued...)
General purpose byte or word transfer instructions
MOV Copy byte or word from specified source to specified
destination
PUSH Copy specified word to top of stack
POP Copy word from top of stack to specified
location
XCHG Exchange bytes or exchange words
XLAT Translate a byte in AL using a table in
memory
Simple input and output port transfer instructions
IN Copy a byte or word from specified port to
accumulator
OUT Copy a byte or word from accumulator to
specified port

6/3/21 4
Instruction Set (continued...)
Special address transfer instructions:
LEA Load effective address of operand into specified
register
LDS Load DS register and other specified register from
memory
LES Load ES register and other specified register from
memory
Flag transfer instructions
LAHF Load (copy to ) AH with the low byte of the flag
register
SAHF Store (copy) AH register to low byte of flag
register
PUSHF Copy flag register to top of stack
POPF Copy word at top of stack to flag register

Instruction Set (continued...) 6/3/21 5


Instruction Comments
MOV DS, 5000H Not Valid; immediate addressing with
segment registers not permitted

MOV AX, 5000H; Immediate addressing


MOV DS, AX Register addressing
MOV AX, [2000H] Direct addressing
MOV AX, [SI] Indirect addressing
MOV AX , 50H[BX] Register relative / Indexed addr
• Push Higher Byte AH into the location
PUSH AX pointed by SP and Push Lower Byte AL
PUSH DS into the location pointed by SP-1;
PUSH [5000H] SPSP-2
• Content of loc. 5000H followed by
5001H in DS are pushed into the stack
Instruction Set (continued...) 6/3/21 6
Do not click the mouse to see the full animation

Example 1 :
*Knowing that,
DS=2042H.
SI=500H, AH AL
AX=214E, 21 4E

MOV [SI], AX 21 20921H


4E 20920H

SI=500

DS=2042H DS=20420H

Instruction Set (continued...) 6/3/21 7


Example 2 :
Physical Address
PUSH AX
Stack Segment

AH AL 20000 SS = 2000
88 44 SP =

44 2FFFB FFFB
88 2FFFC FFFC
XX 2FFFD FFFD
XX 2FFFE FFFE
XX 2FFFF FFFF

Instruction Set (continued...) 6/3/21 8


Instruction Comments

• Pops stack top content pointed by SP into


Lower Byte of the register / mem. location
1. POP AX
2. POP DS and next byte in the stack into Higher Byte
3. POP [5000H] of the register / mem. location ; SPSP+2
• Content of stack top and next byte in the
stack are popped into 5000H & 5001H in
DS
1. XCHG [5000H], AX
2. XCHG BX, AX
• Exchanges data b/w AX &
mem.loc [5000H] in data seg.
1. IN AL, 03H •Exchange data b/w AX & BX
2. IN AX, DX
3. MOV DX, 0800H 03H is 8-bit port address
IN AX, DX [DX] is 6-bit port address

Instruction Set (continued...) 6/3/21 9


Example 3 :
Physical Address
POP AX
Stack Segment

AH AL 20000 SS = 2000
xx
88 xx
44 SP =

44 2FFFB FFFB
88 2FFFC FFFC
XX 2FFFD FFFD
2FFFE FFFE
2FFFF FFFF

Instruction Set (continued...) 6/3/21 10


Instruction Comments

1. Send data in AL to a port whose


1. OUT 03H, AL
address is 03H
2. OUT DX, AX 2. Send data in AX to a port whose
3. MOV DX, 0300H address is in DX
OUT DX, AX 3. Send data in AX to a port whose
address is in DX, set as 0300H

Instruction Set (continued...) 6/3/21 11


Example 4 :

• XLAT called translate instruction.


• The operation of XLAT is to change the value of AL with the memory pointed
to by (AL+BX)
AL Mem[AL+BX]

dddd+mmmm data

AL=dddd

BX=mmmm AL=data

for the example slides do not click the mouse to see the full animation

Instruction Set (continued...) 6/3/21 12


More clearly the XLAT instruction converts the
content of register AL, using a table. Its beginning
address is contained in register BX. The content of
register AL is interpreted as a relative address in the
table.

• XLAT is the only instruction that adds 8 bit number


to 16 bit number!

• XLAT does not Affect the flags..

Instruction Set (continued...) 6/3/21 13


1 2 83
KB(0-F) 8255 8086 CPU
User 16-Keys KBD 4 AL BX 5
interface 7
7-seg 9 6
Display

LUT
-
-
-
LUT- Mem.Seg
Example 5 :
Program using XLAT Comments

1. Address of seg containing


MOV AX, SEG TABLE LUT is stored in DS
MOV DS, AX 2. Code of key pressed
MOV AL, CODE transferred to AL
MOV BX, OFFSET TABLE 3. Offset of code LUT into BX
XLAT used as Base Addr by XLAT
EffectAddr =10*SEG + BX+AL
4. AL [10*SEG + BX+AL]
8086 Instruction Set (continued...) 6/3/21 14
Instruction Comments
1. LEA BX, ADR 1. BX  Offset (ADR)
2. LEA SI, ADR[BX] 2. SI  Offset (ADR) + [BX]
3. LDS BX, 5000H 3. BX(LB)  [5000H]
4. LES BX, 5000H BX(HB)  [5001H]
DS/ES(LB)  [5002H]
DS/ES(HB)  [5003H]

Note: Effective Address is also called as Offset

8086 Instruction Set (continued...) 6/3/21 15


Instruction Comments
1. LAHF 1. AH  [Flag (LB)]
2. SAHF 2. Set/Reset all condition code flags except
Overflow flag
3. PUSHF 3. SP  SP-2; for each PUSH operation;
Push FlagRegr(HB) followed by
FlagRegr(LB) into the stack SS:SP
4. POPF
4. SP  SP+2; for each POP operation;
Pop into FlagRegr(LB) followed into
FlagRegr(HB) from stack SS:SP

8086 Instruction Set (continued...) 6/3/21 16


8086 INSTRUCTION SET
1. Data Copy / Transfer Instructions
2. Arithmetic Instructions
3. Logical Instructions
4. Shift and Rotate Instructions
5. String Manipulation Instructions
6. Branch and Loop Instructions
5. Flag Manipulation Instructions
6. Machine Control Instructions

8086 Instruction Set (continued...) 6/3/21 17


2. ARITHMETIC INSTRUCTIONS

Performs
 Addition,
 Subtraction,
 Multiplication,
 Division,
 Increment,
 Decrement

along with ASCII and Decimal adjustment

 Operands in : Immediate / Register / Memory locn.


 Note: Flag bits in flag register are affected

8086 Instruction Set (continued...) 6/3/21 18


Addition instructions:
ADD Add specified byte to byte or specified word to
word
ADC Add byte + byte + carry flag (or)
word + word + carry flag
INC Increment specified byte or specified word by 1
AAA ASCII adjust after addition
DAA Decimal (BCD) adjust after addition
Multiplication instructions
MUL Multiply unsigned byte by byte or unsigned word
by word
IMUL Multiply signed byte by byte or signed word by
word
AAM ASCII adjust after multiplication

8086 Instruction Set (continued...) 6/3/21 19


Subtraction Instructions:
SUB Subtract byte from byte or word for word
flag from word.
SBB Subtract byte and carry flag from byte or word ad
carry
DEC Decrement specified byte or specified word by 1
NEG Negate – invert each bit of a specified byte or word
and add 1. (form 2’s complement)
CMP Compare two specified bytes or two specified
words
AAS ASCII adjust after subtraction
DAS Decimal (BCD) adjust after subtraction

8086 Instruction Set (continued...) 6/3/21 20


Division Instructions:
DIV Divide unsigned word by byte or unsigned DW by
word
IDIV Divide signed word by byte or signed DW by word
AAD ASCII adjust before division
CBW Fill upper byte of word with copies of sign bit of
lower byte
CWD Fill upper word of DW with sign bit of lower word

8086 Instruction Set (continued...) 6/3/21 21


• Result is in destination operand
• All the condition code flags are affected
• Content of segment registers cannot be added
• Memory to memory addition not possible
ADD Add
1. ADD AX, 0100H 1. Immediate addressing
2. ADD AX, BX 2. Register addressing
3. ADD AX, [SI] 3. Indexed / indirect addressing
4. ADD AX, [5000H] 4. Direct addressing
5. ADD [5000H], 0100H 5. Immediate addressing
6. ADD 0100H 6. Implicit addressing

(destination AX) &
Source : Regr / Mem.Locn / immediate
• Destination : Regr / Mem.Locn immediate addressing

8086 Instruction Set (continued...) 6/3/21 22


• Same as ADD instruction
• Adds the carry flag bit with the result.
• All the condition code flags are affected
ADDC Add with carry
1. ADC 0100H 1. Immediate addressing
2. ADC AX, BX 2. Register addressing
3. ADC AX, [SI] 3. Indexed / indirect addressing
4. ADC AX, [5000H] 4. Direct addressing
5. ADC [5000H], 0100H 5. Immediate addressing
6. ADD 0100H 6. Implicit addressing
(destination AX) &
• Source : Regr / Mem.Locn / immediate
• Destination : Regr / Mem.Locn
immediate addressing

8086 Instruction Set (continued...) 6/3/21 23


• Register/Mem.content incremented / decremented by 1
• All the condition code flags are affected except CF
• Immediate operand cannot be incremented
INC Increment
1. INC AX 1. Register addressing
2. INC [BX] 2. Register indirect addressing
3. INC [5000H] 3. Direct addressing

DEC Decrement
1. DEC AX 1. Register addressing
2. DEC [BX] 2. Register indirect addressing
3. DEC [5000H] 3. Direct addressing

8086 Instruction Set (continued...) 6/3/21 24


• Destn.operand  Destn.operand – Source operand
• All the condition code flags are affected

SUB Subtract
1. SUB AX, 0100H 1. Immediate addressing
2. SUB AX, BX 2. Register addressing
3. SUB AX, [SI] 3. Indexed / indirect addressing
4. SUB AX, [5000H] 4. Direct addressing
5. SUB [5000H], 0100H 5. Immediate addressing

• Source : Regr / Mem.Locn / immediate


• Destination : Regr / Mem.Locn

8086 Instruction Set (continued...) 6/3/21 25


• Destn.operand  Destn.operand – (Source operand + CF)
• All the condition code flags are affected

SBB Subtract with borrow


1. SBB AX, 0100H 1. Immediate addressing
2. SBB AX, BX 2. Register addressing
3. SBB AX, [SI] 3. Indexed / indirect addressing
4. SBB AX, [5000H] 4. Direct addressing
5. SBB [5000H], 0100H 5. Immediate addressing

• Source : Regr / Mem.Locn / immediate


• Destination : Regr / Mem.Locn

8086 Instruction Set (continued...) 6/3/21 26


• Destn.operand – Source operand
• Result not stored anywhere
• All the condition code flags are affected
• ZF=1(equal); CY=1 (src > destn); CY =0, ZF=0 (src < destn)

CMP Compare
1. CMP AX, 0100H 1. Immediate addressing
2. CMP BX, 0100H 2. Immediate addressing
3. CMP BX, [SI] 3. Indexed / indirect addressing
4. CMP BX, CX 4. Register addressing
5. CMP [5000H], 0100H 5. Direct/Immediate addressing

• Source : Regr / Mem.Locn / immediate


• Destination : Regr / Mem.Locn

8086 Instruction Set (continued...) 6/3/21 27


AAA ASCII Adjust after addition

• Executed after ADD


• ADD must have added two ASCII no’s & result is in AL
• AAA converts AL to unpacked decimal digits(Implicit addressing)
AX AH (8 bits) AL (8 bits)

ALHIGH ALLOW

(1) If 0 < ALLOW < 9 and AF=0, then ALHIGH = 0


(2) If 0 < ALLOW < 9 and AF=1,
then ALLOW = ALLOW +06 and ALHIGH = 0 and AH=AH+1

(3) If ALLOW > 9, then AL=AL+06H and ALHIGH = 0 and


AH=AH+1, ACF=CF= 1

8086 Instruction Set (continued...) 6/3/21 28


DAA Decimal Adjust Accumulator

• Executed after adding two packed BCD numbers


• Converts packed BCD numbers to unpacked BCD no’s
• Result has to be in AL
AX AH (8 bits) AL (8 bits)

(1) If ALLOW > 9 ALHIGH ALLOW


OR
if AF=1, then DAA adds 06H to AL
(2) After adding 06H to AL, if ALHIGH > 9
OR
if CF=1, then DAA adds 60H to AL.

8086 Instruction Set (continued...) 6/3/21 29


8086 INSTRUCTION SET
1. Data Copy / Transfer Instructions
2. Arithmetic Instructions
3. Logical Instructions
4. Shift and Rotate Instructions
5. String Manipulation Instructions
6. Branch and Loop Instructions
5. Flag Manipulation Instructions
6. Machine Control Instructions

8086 Instruction Set (continued...) 6/3/21 30


3. LOGICAL INSTRUCTIONS

Logical Instructions:
NOT Logical Invert: Invert each bit of a byte or word
in another byte or word
AND Logical AND: AND each bit in a byte or word with
the corresponding bit
OR Logical OR: OR each bit in a byte or word with the
corresponding bit in another byte or word
XOR Logical XOR: Exclusive OR each bit in a byte or
word with the corresponding bit in another byte or
word
TEST Logical Compare: AND operation to update flags,
[OF, CF, SF, ZF, PF] but don’t change operands

8086 Instruction Set (continued...) 6/3/21 31


3. LOGICAL INSTRUCTIONS

Logical Instructions:
NOT NOT AX;
NOT [5000H];
AND AND AX, 0008H;
AND AX, BX;
AND [5000H], DX;
OR OR AX, 0008H;
OR AX, BX;
OR DX, [5000H];
XOR XOR AX, 0098H; XOR AX, BX; XOR AX, [5000H];
TEST TEST AX, BX; TEST [5000H] 06H;
TEST [BX][DI], CX

8086 Instruction Set (continued...) 6/3/21 32


8086 INSTRUCTION SET
1. Data Copy / Transfer Instructions
2. Arithmetic Instructions
3. Logical Instructions
4. Shift and Rotate Instructions
5. String Manipulation Instructions
6. Branch and Loop Instructions
5. Flag Manipulation Instructions
6. Machine Control Instructions

8086 Instruction Set (continued...) 6/3/21 33


4. SHIFT AND ROTATE INSTRUCTIONS
SHIFT INSTRUCTIONS

Shift Instructions (count is either 1 or specified by CL)


SHL/ Shift Left / Shift Arithmetic Left:
SAL Shift bits of byte or word left, put zero(s) in LSB(s).
SHR Shift Right:
Shift bits of byte or word right, put zero(s) in MSB(s).
SAR Shift Arithmetic Right:
Shift bits of word or byte right, copy old MSB into new MSB

8086 Instruction Set (continued...) 6/3/21 34


SHL/ SAL Shift bits of byte or word left, put zero(s) in LSB(s)
1. All flags are affected 2. Shift is through Carry Flag
3. Operand may reside in Register or Mem. Location but
not immediate
x0 Carry Flag
MSB LSB
SHL / SAL
1st execution 0 1 0
1 1 1
0 01 0 1
0 0
1

1 Carry Flag
MSB LSB
SHL / SAL
2nd execution 1 0 1 0 0 1 0 0

8086 Instruction Set (continued...) 6/3/21 35


SHR Shift bits of byte or word right, put zero(s) in MSB(s).
1. All flags are affected 2. Shift is through Carry Flag
3. Operand may reside in Register or Mem. Location
Carry Flag
MSB LSB
0 1 1 0 1 0 0 1 x

SHR 1st execution 0 0 1 1 0 1 0 0 1

SHR 2nd execution 0 0 0 1 1 0 1 0 0

8086 Instruction Set (continued...) 6/3/21 36


SAR Shift bits of word or byte right, copy old MSB into
new MSB
1. All flags are affected 2. Shift is through Carry Flag
3. Operand may reside in Register or Mem. Location
Carry Flag
MSB LSB
1 0 1 0 1 0 0 1 x

SHR 1st execution 1 1 0 1 0 1 0 0 1

SHR 2nd execution 1 1 1 0 1 0 1 0 0

8086 Instruction Set (continued...) 6/3/21 37


4. SHIFT AND ROTATE INSTRUCTIONS
ROTATE INSTRUCTIONS
Rotate Instructions (count is either 1 or specified by CL)
ROL Rotate Left without Carry: Rotate bits of byte or word
left, MSB to LSB and to CF
ROR Rotate Right without Carry: Rotate bits of byte or word
right, LSB to MSB and to CF
RCL Rotate Left through Carry: Rotate bits of byte or word
left, MSB to CF and CF to LSB
RCR Rotate Left through Carry: Rotate bits of byte or word
right, LSB to CF and CF to MSB

8086 Instruction Set (continued...) 6/3/21 38


ROL Rotate bits of byte or word left, MSB to LSB and to CF
RCL Rotate bits of byte or word left, MSB to CF and CF to LSB

 ROL vs. RCL


x10 Carry Flag
MSB LSB
ROL 0 0
1 1 1
0 0
1 01 1
0 0
1 1
0
21nd
st
execution
execution

Carry Flag
x
1
0

MSB LSB
RCL
1 1
0 0 0
1 0
1 1
0 x
0 0
1 1 1
x x
0
321 execution
rd
nd
st
execution

8086 Instruction Set (continued...) 6/3/21 39


8086 INSTRUCTION SET
1. Data Copy / Transfer Instructions
2. Arithmetic Instructions
3. Logical Instructions
4. Shift and Rotate Instructions
5. String Manipulation Instructions
6. Branch and Loop Instructions
5. Flag Manipulation Instructions
6. Machine Control Instructions

8086 Instruction Set (continued...) 6/3/21 40


5. STRING MANIPULATION INSTRUCTIONS
String Instructions
REP An instruction prefix. Repeat following
instruction until CX=0
REPE/REPZ Repeat while equal/zero
REPNE/REPNZ Repeat while not equal/zero
MOVX/MOVSB/ Move byte or word from one string to another
MOVSW
COMPS/COMPSB/ Compare two string bytes or two string words
COMPSW
SCAS/SCASB/ Scan a string. Compare a string byte with a byte
SCASW in AL or a string word with a word in AX
LODS/LODSB/ Load string byte into AL or string word into AX
LODSW
STOS/STOSB/STOSW Store byte from AL or word from AX into string

8086 Instruction Set (continued...) 6/3/21 41


8086 INSTRUCTION SET
1. Data Copy / Transfer Instructions
2. Arithmetic Instructions
3. Logical Instructions
4. Shift and Rotate Instructions
5. String Manipulation Instructions
6. Branch and Loop Instructions
5. Flag Manipulation Instructions
6. Machine Control Instructions

8086 Instruction Set (continued...) 6/3/21 42


6. BRANCH AND LOOP INSTRUCTIONS

1. Unconditional Branch Instructions


2. Conditional Branch Instructions
3. Loop Instructions

Unconditional Branch Instructions:


CALL Call a procedure (subprogram), save return
address on stack
RET Return from procedure to calling program
JMP Go to specified address to get next instruction

8086 Instruction Set (continued...) 6/3/21 43


Conditional Branch Instructions
JA/JNBE Jump if above/ jump if not below or equal
JAE/JNB Jump if above or equal/ jump if not below
JB/JNAE Jump if below/ jump if not above or equal
JC Jump if carry =1
JBE/JNA Jump if below or equal/ jump if not above
JE/JZ Jump if equal/ jump if zero
JG/JNLE Jump if greater/ jump if not less than or equal
JGE/JNL Jump if greater than or equal/ jump if not less than
JL/JNGE Jump if less than/ jump if not greater than or equal
JLE/JNG Jump if less than or equal/ jump if not greater than
JNC Jump if no carry
JNE/JNZ Jump if not equal/ jump if not zero

8086 Instruction Set (continued...) 6/3/21 44


Conditional Branch Instructions
JNO Jump if no overflow
JNP/JPO Jump if not parity/ jump if parity odd (PF = 0)
JNS Jump if not sign
JO Jump if overflow
JP/JPE Jump if parity/ jump if parity even
JS Jump if sign
Interrupt Instructions:
INT Interrupt program execution, call service
procedure
INTO Interrupt program execution if OF=1
IRET Return from interrupt service procedure to
main program

8086 Instruction Set (continued...) 6/3/21 45


Loop Instructions
LOOP Loop through a sequence of
instructions until CX=0
LOOPE/LOOPZ Loop through a sequence of
instruction while ZF=1 and CX !=0
LOOPNE/LOOPNZ Loop through a sequence of
instruction while ZF=0 and CX!=0.
JCXZ Jump to specified address if CX=0.

8086 Instruction Set (continued...) 6/3/21 46


8086 INSTRUCTION SET
1. Data Copy / Transfer Instructions
2. Arithmetic Instructions
3. Logical Instructions
4. Shift and Rotate Instructions
5. String Manipulation Instructions
6. Branch and Loop Instructions
7. Flag Manipulation Instructions
8. Machine Control Instructions

8086 Instruction Set (continued...) 6/3/21 47


7. FLAG MANIPULATION INSTRUCTIONS

Flag Manipulation Instructions:


STC Set carry flag
CLC Clear carry flag
CMC Complement the status of carry flag
STD Set direction flag
CLD Clear direction flag
STI Set interrupt enable flag (enable INTR)
CLI Clear interrupt enable flag (disable INTR)

8086 Instruction Set (continued...) 6/3/21 48


8086 INSTRUCTION SET
1. Data Copy / Transfer Instructions
2. Arithmetic Instructions
3. Logical Instructions
4. Shift and Rotate Instructions
5. String Manipulation Instructions
6. Branch and Loop Instructions
7. Flag Manipulation Instructions
8. Machine Control Instructions

8086 Instruction Set (continued...) 6/3/21 49


8. MACHINE CONTROL INSTRUCTIONS

Machine Control Instructions:


HLT Halt until interrupt or reset
WAIT Wait until signal on the TEST pin is low
LOCK An instruction prefix.
Prevents another processor from taking the bus
while the adjacent instruction executes
NOP No action except fetch and decode

8086 Instruction Set (continued...) 6/3/21 50

You might also like