8086 Instruction Set
Instruction Set of 8086/8088
The instruction set of 8086 is divided into 8
major groups as follows:
1. Arithmetic and Logic Instructions
2. Data Movement Instructions (remember
addressing modes)
3. String Instructions
4. Program Control Transfer Instructions
5. Iteration Control Instructions
6. Processor Control Instructions
7. External Hardware Synchronization Instructions
8. Interrupt Instructions
2
Arithmetic and Logic Instructions
The Arithmetic and Logic Instructions include
1. Addition instruction
2. Subtraction instruction
3. Multiplication instruction
4. Division
5. BCD and ASCII arithmetic instruction
6. Comparison
7. Basic Logic Instructions-AND, OR, NOT,
XOR
8. Shift and rotate instruction
3
Addition instruction
this group of instruction consist of the
following instructions:
ADD destination, source
– These instructions add a number from
source to a number from destination and
put the result in the destination.
– E.g: ADD AL, 0F0H ; will add immediate
number 0F0H to contents of AL.
– ADD DX, BX; ;will add the content
of BX to content of DX
4
Addition instruction
ADD destination, source
– Example: write a program that adds the
following:
4567H+ADC7H
Solution
– MOV AX, 4567H;
– ADD AX, 0ADC7H; or
» MOV AX, 4567H;
» MOV DX, 0ADC7H;
» ADD AX, DX;
5
Addition instruction
ADC destination, source
– These instructions add a number from
source to a number from destination and
also will add the content of carry register
put the result in the destination.
– E.g: ADC DL, CL; will add contents of
CL to contents of DL with carry and store
result DL. i.e. DL=DL+CL+CF
– Example: run the following program and
check the content of DX:
– MOV AX, 0FBB7H;
– ADC AX, 0ADBBH; 6
Addition instruction
INC instruction
– This instruction adds 1 to the specified
destination. The destination may be a
register or memory location. The AF, OF,
PF, SF and ZF flags are affected.
INC AL; add 1 to the content of AL.
INC BX; add 1 to content of BX.
Example: save the number AB45H on DX
register and increment it by 1.
– MOV DX, AB45H;
– INC DX;
7
Addition instruction
INC instruction
– This instruction adds 1 to the specified
destination. The destination may be a
register or memory location. The AF, OF,
PF, SF and ZF flags are affected.
INC AL; add 1 to the content of AL.
INC BX; add 1 to content of BX.
Example: save the number AB45H on DX
register and increment it by 1.
– MOV DX, AB45H;
– INC DX;
8
Subtraction instruction
Subtraction: has the following instruction
– SUB: subtraction
– SBB: Subtraction with borrow
– DEC: Decrement (subtract 1)
– NEG: calculates 2’s complement of a
number
– Example:
SUB
AL, 0F0H ; subtract immediate
number 0F0H from AL.
SBB DL,CL ;subtract contents of CL and status
of carry flag from
contents of AL store result in AL. 9
DL=DL-CL-CF
Comparison instruction
CMP: instruction compares a byte or word
from the specified source with a byte or
word from the specified destination. The
source and destination both must be byte or
word.
Note: during CMP instruction the result is not
stored in the destination. But by CMP
instruction only the content of flags are
affected. Examples:
– CMP BL, 01H ; compare immediate number 01H
with CL.
– CMP CX, BX ;compare word in BX with word in CX.
– CMP CX, TOTAL ; compares word at a 10
Multiplication instruction
Two instructions for multiplication
– MUL : unsigned multiplication i.e. positive
number multiplication
– IMUL : signed multiplication
– Example:
MUL BL ;AX=AL*BL
MUL BX ; this instruction multiplies the
content of AX and BX and stores the result’s
high word on DX and low word on AX. Because
multiplying two 16 bits the result is 32 bit
word.
MUL BL ;AX=AL*BL but here AL and BL can be
negative or positive numbers
MUL 11
BX ; this instruction multiplies the
Division instruction
Two instructions for multiplication
– DIV : unsigned division i.e. division on positive
number.
– IMUL : signed division
– Example:
DIV CL ;this instruction divides a word in
AX by CL and stores the Quotient in
AL and the reminder in AH.
DIVCX ; this instruction divides a word in
DX by a Word in AX and put the
Quotient in AX and the r
reminder in DX.
IDIV instruction is similar to DIV instruction but
IDIV can operate on both positive and negative12
Example
1. Write a program that will subtract 6 from a
numbers that is inputted by a user and displays
the result on the 8086’s LED display.
– Solution :
IN AX, 112;
SUB AX, 6H;
OUT 199, AX;
2. Write a program that will subtract two numbers
that is inputted by a user and displays the result
on the 8086’s LED display.
– Solution: note: the program perform port 110-
port 112
IN AX, 112;
MOV DL, AL;
13
IN AX, 110;
Example
3. Write a program that will take an input from port 112
increments it by one and then subtract 7 from it and
then display the result on 8086’s LED port.
– Solution:
IN AX, 112;
INC AX;
SUB AX, 7H;
OUT 199, AX;
4. Write a program that will Multiply the numbers 12H and
DFH and display the result on LED display.
– Solution
MOV AL, 12H;
MOV DL, 0DFH;
MUL DL;
OUT 199, AX;
14
Example
5. Write a program that divides the number ADC4H
by EFH and displays the result on the LED display.
– Solution:
MOV AX, 0ADC4H;
MOV CL, 0EFH;
DIV CL;
MOV AH, 0H;
OUT 199, AX;;
15
Basic Logic Instructions
The basic logic instruction include AND, OR,
Exclusive-OR, and Not instruction.
AND instruction
– AND destination, source
– E.g: AND BL, AL ; this instruction ands byte in AL with byte
in BL.
– E.g: AND CX, 00F0H ; this instruction ands byte in CX with
00F0H and
stores the result in CX.
OR instruction
– OR destination, source
– E.g: AND BL, AL ; this instruction ors byte in AL with byte
in BL and stores the result in
BL.
– E.g: OR CX, 00F0H ; this instruction ors byte in CX with 16
Basic Logic Instructions
XOR instruction
– XOR destination, source
– E.g: XOR BL, AL ; this instruction XOR byte in AL with Byte
in BL and stores the result in BL.
NOT instruction
– Syntax: NOT AL ; this instruction negates the byte in AL.
17
String Instructions
The 8086 instruction set provides the following
string instruction:
– REP, REPE, REPZ, REPNE, REPNZ
– MOVS, MOVSB, MOVSW
– LODS, LODSB, LODSW
– STOS, STOSB, STOSW
– SCAS, SCASB, SCASW
18
Program Transfer Instructions
Two types of Program control instructions
1. Unconditional transfer instructions
CALL, RET and JUMP
2. Conditional transfer instructions
J cond
19
CALL and RET Instructions
CALL and RET Instructions
– Whenever we need to instructions several times
throughout a program there are two ways to
To write the group of instructions as a separate
procedure . We can just CALL the procedure whenever
we need to execute that group of instructions. For calling
the procedure we have to store the return address onto
the stack. This process takes some time. If the group of
instruction is big enough then this overhead time is
negligible wrt execution time. But if the group of
instruction is too short , the overhead time are
comparable. In such cases, it is not desirable to write
procedures. For this cases, we can use macros. Macro is
a group of instructions. Each time we call a macro in our
program, the assembler will insert the defined group of
instructions in place of the “CALL”. An important point
here is that the assembler generates machine codes for 20
CALL and RET Instructions
The syntax for CALL instruction is:
– Direct or within segment (near)
CALL PRO ; PRO is the name of the procedure.
; the assembler determines displacement of pro
from the instruction after the CALL and
codes this displacement in as part of the
instruction.
– Indirect- Within-segment (near)
CALL CX ; CX contains the offset of the first instruction
of the procedure. Replace
content of IP with contents of
register CX.
– Indirect to another segment (far)
CALL DWORD PTR[BX] ; new values for CS and IP are
fetched from 4 memory
locations in DS. The new value for CS is 21
CALL and RET Instructions
RET instruction
– The RET instruction will return execution
from a procedure to the next instruction
after the CALL instruction in the calling
program.
– If the procedure is near procedure (in the
same code segment as the call
instruction), then the return will be done
by replacing the instruction pointer with a
word from the top of the stack.
22
JUMP Instructions
JUMP and Loop instruction
JMP Jump
JZ Jump if Zero i.e. JUMP if AX=1
JNZ Jump if not zero i.e. Jump if AX=0
JO Jump if Overflow i.e. Jump if OF=1
JNO Jump if no Overflow i.e. Jump if
OF=0
JC Jump if there is carry i.e. jump if CF=1
JNC Jump if there is no carry i.e. jump if
CF=0.
JS Jump if sign i.e. jump if SF=1
JNS Jump if no sign i.e. Jump if SF=0 23
JUMP Instructions
JUMP and Loop instruction
JPO Jump parity odd JUMP if PF=0
JPE Jump if parity even i.e. JUMP if PF=1
JA Jump above i.e. Jump if (CF and ZF)=0
JB Jump if below i.e. Jump if CF=0
JAE Jump if Above or equal i.e. Jump if (CF
or ZF)=1
JG Jump if greater i.e. jump if (ZF=0 and
SF=Of)
JL Jump if Less i.e. jump if SF<>OF.
JGE Jump if greater or equal i.e. jump if
SF=OF
24
JLE Jump if Less or equal i.e. Jump if (ZF=1
JUMP Instructions
Example: If AH=10
» CX=CX+100H;
Solution:
MOV AH, 10H;
CMP AH, 10H;
JZ Lable1;
Lable1: ADD CX,10H;
25
Answers to Group Assignment
Question 1 (A) answer: May have many
solution
org 100h
org 100h
MOV DX,45;
MOV DX,45;
CMP DX,45
CMP DX,45
JZ Lable1;
JNZ Lable1
MOV CX,DX
MOV AX,2;
JMP Exit;
MUL DX;
Lable1:
MOV CX,AX;
MOV AX,2;
JMP Exit;
MUL DX;
Lable1: MOV CX,DX
MOV CX,AX;
Exit: ret
Exit: ret
26
Answers to Group Assignment
Question 1 (b) answer: May have many
solution
org 100h
org 100h
MOV DX,67;
MOV DX,67;
CMP DX,45
CMP DX,45
JZ Lable1;
JNZ Lable1
MOV CX,DX
MOV AX,2;
JMP Exit;
MUL DX;
Lable1:
MOV CX,AX;
MOV AX,2;
JMP Exit;
MUL DX;
Lable1: MOV CX,DX
MOV CX,AX;
Exit: ret
Exit: ret
27
Answers to Group Assignment
Question 2 answer: have Many solutions
org 100h org 100h
MOV CX,0; MOV CX,10;
MOV DX,10; MOV DX,0;
CMP DX,0;
LOOP: ADD CX,DX;
LOOP1: ADD DX,CX;
DEC DX; LOOP LOOP1;
JZ Exit Exit: MOV AX, DX;
JMP LOOP; OUT 199, Ax;
Exit: MOV AX, CX; ret
OUT 199, Ax;
ret
28
Thank You