UNIT-4 8086 Instruction
UNIT-4 8086 Instruction
Microprocessor
1
Assignment of codes to Registers
2
Types of instruction set of 8086
microprocessor
(1). Data Copy/Transfer instructions.
3
(1). Data copy/transfer instructions.
data.
Destination can be register or memory operand.
Both Source and Destination cannot be memory location
BEFORE AFTER
EXECUTION EXECUTION
A AL A AL
H H
B BL MOV B BL
H
40
CL,M; H
40
C CL C CL 40
H H
D D D D
H L H L 5
Stack Pointer
It is a 16-bit register, contains the address of the data
item currently on top of the stack.
6
(1). Data copy/transfer instructions.
E.g.:
(1). PUSH AX;
(2). PUSH DS;
(3). PUSH [5000H]; 7
INITIAL POSITION
(1) STACK
POINTER
DECREMENTS SP & STORES HIGHER
BYTE
8
BEFORE EXECUTION
SP 2002H
2000H
BH BL
2001H
CH 10 CL 50
DH DL 2002H
PUSH CX
AFTER
50
EXECUTION
SP 2000H 2000H
BH BL
2001H 10
CH 10 CL 50
DH DL 2002H
9
(1). Data copy/transfer instructions.
E.g.
(1). POP AX;
(2). POP DS;
(3). POP [5000H]; 10
INITIAL POSITION AND READS LOWER
BYTE
(1) STACK
POINTER LOWER BYTE
INCREMENTS SP
LOWER BYTE
HIGHER BYTE
(3) STACK
POINTER
11
BEFORE
EXECUTION
2000H30
S 2000H
P 2001H50
B B
H L 2002H
POP BX
AFTER
EXECUTION 2000H30
SP 2002H 2001H50
B 5 B 3 2002H
H 0 L 0 12
(1). Data copy/transfer instructions.
•E.g.
(1). XCHG BX, AX;
(2). XCHG [5000H],AX;
13
BEFORE AFTER EXECUTION
EXECUTION
A 20 AL 40 AH 70 AL 80
H
B 70 BL 80 BH 20 BL 40
H
XCHG
AX,BX; 14
(1). Data copy/transfer instructions.
address.
E.g.
PORT 10 AL
80H
IN
AL,80H;
AFTER EXECUTION
PORT 10 AL 10
80H
16
(1). Data copy/transfer instructions.
address.
E.g.
PORT 10 AL 40
50H
OUT
50H,AL;
AFTER EXECUTION
PORT 40 AL 40
50H
18
(1). Data copy/transfer instructions.
(7). XLAT;
Mnemonic Meaning Format Operation Flags
XLAT Translate XLAT ((AL)+(BX)+(DS)0) (AL) None
20
(1). Data copy/transfer instructions.
E.g.
(1). LEA BX,Address;
(2). LEA SI,Address[BX]; 21
(1). Data copy/transfer instructions.
address (dest.);
LDS Also known as Load Data Segment (LDS).
LES Also known as Load Extra Segment (LES).
It loads the contents of DS (Data Segment) or ES (Extra
Segment) & contents of the destination to the contents of
source register.
E.g.
(1). LDS BX,5000H;
(2). LES BX,5000H; 22
(1). LDS BX,5000H;
(2). LES BX,5000H;
15 0 7 0
BX 20 10 10 5000H
20
5001H
30 5002H
DS/ 40 30
ES 40 5003H
23
(1). Data copy/transfer instructions.
25
(2). Arithmetic
Instructions
These instructions perform the operations like:
Addition,
Subtraction,
Increment,
Decrement.
26
(2). Arithmetic
Instructions
(1). ADD destination, source;
A 1 A 1 A 3 A 3
H 0 L 0 ADD H 0 L 0
B 2 B 2 AX,BX B 2 B 2
H 0 L 0 H 0 L 0
2050 28
(2). Arithmetic
Instructions
(2). ADC destination, source
This instruction adds the contents of source
operand with the contents of destination operand
with carry flag bit.
The source may be immediate data, memory
location or register.
The destination may be memory location or register.
The result is stored in destination operand.
AX is the default destination register.
AH 10 AL 10 INC AH 10 AL 11
AX
AH 10 AL 10 DEC AH 10 AL 0F
AX
A 20 AL 00 SUB A 10 AL 00
H H
AX,1000H
2000
-1000
=1000
A 20 AL 00 A 10 AL 00
H SUB H
B 10 BL 00 AX,BX B 10 BL 00
H H 36
(2). Arithmetic
Instructions
(6). SBB destination, source;
Also known as Subtract with Borrow.
This instruction subtracts the contents of source
operand & borrow from contents of destination
operand.
The source may be immediate data, memory
location or register.
The destination may be memory location or register.
The result is stored in the destination place.
AL 0 7 AFTER
EXECUTION
Hb Lb
Hb=Higher
bits,
(1). FOR Lb=Lower bits.
AL>09H
6 A
AL BEFORE
Hb Lb EXECUTION
(A)1010
HB LB
+(06)0110=0001
AL 0
0000 0 AFTER
Hb Lb EXECUTION
42
(2). Arithmetic
Instructions
(9). AAS
Also known as ASCII Adjust After Subtraction.
This instruction is executed after SUB instruction.
AL 0 7 AFTER
EXECUTION
Hb Lb
Hb=Higher
bits,
(1). FOR Lb=Lower bits.
AL>09H
6 A
AL BEFORE
Hb Lb EXECUTION
(A)1010 -
Hb Lb
(06)0110=0000 0100
AL 0 4 AFTER
Hb Lb EXECUTION
44
(2). Arithmetic
Instructions
(10). AAM
Also known as ASCII Adjust After Multiplication.
This instruction is executed after MUL
instruction.
Then AH=AL/10 & AL=Remainder.
58
•
(3). Logical Instructions
(4). TEST destination,source
Both operands may be register, memory location or
immediate data.
This instruction performs bit by bit logical AND
operation for flags only (i.e. only flags will be affected).
If the corresponding 0th bit of result contains ‘1’ then
result will be non-zero & zero flag will be cleared/reset
(i.e. ZF=0).
If the corresponding 0th bit of result contains ‘0’ then
result will be zero & zero flag will be set (i.e. ZF=1)..
59
(3). Logical Instructions
(5).Shift and Rotate
Instructions
SHL/SAL: shift logical left/shift arithmetic
left
SHR: shift logical right
SAR: shift arithmetic right
ROL: rotate left
ROR: rotate right
RCL: rotate left through carry
RCR: rotate right through carry
60
SHL Instruction
The SHL (shift left) instruction performs a logical left shift on
the destination operand, filling the lowest bit with 0.
0
CF
• Operand types:
SHL reg,imm8
SHL mem,imm8
SHL reg,CL
SHL mem,CL
61
Fast Multiplication
Shifting left 1 bit multiplies a number by 2
mov dl,5
Before: 00000101 =5
shl dl,1
0 0 0 0 1 0 1 0 = 10
After:
Shifting left n bits multiplies the operand by 2n
◦ For example, 5 * 22 = 20
mov dl,5
shl dl,2 ; DL = 20
62
Ex.; Multiply AX by 10
SHL AX, 1
MOV BX, AX
MOV CL,2
SHL AX,CL
ADD AX, BX
63
SHR Instruction
The SHR (shift right) instruction performs a logical right shift
on the destination operand. The highest bit position is filled
with a zero.
0
CF
CF
An arithmetic shift preserves the number's sign.
MOV DL,-80
SAR DL,1 ; DL = -40
SAR DL,2 ; DL = -10
65
(3). Logical Instructions
RCR
Also known as Rotate Right through Carry.
Each binary bit of the operand is rotated
towards right by one position through
Carry flag.
Least Significant Bit (LSB) i.e. B0 is placed
in the Carry flag.
Then carry flag bit is placed in the Most
Significant Bit (MSB) position B15.
66
BEFORE EXECUTION
B B B B B B B B B B B B B B B B CF
1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 1 0
15 7 0
AFTER EXECUTION
B B B B B B B B B B B B B B B B CF
0 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 1
15 7 0
67
(3). Logical Instructions
(6). RCL
Also known as Rotate Left through Carry.
Each binary bit of the operand is rotated
68
BEFORE EXECUTION
CF B B B B B B B B B B B B B B B B
0 1 0 0 1 0 0 1 0 0 0 0 1 0 0 0 1
AFTER EXECUTION
CF B B B B B B B B B B B B B B B B
1 0 0 1 0 0 1 0 0 0 0 1 0 0 0 1 0
69
ROL Instruction
ROL (rotate) shifts each bit to the left
The highest bit is copied into both the Carry flag
CF
MOV Al,11110000b
ROL Al,1 ; AL = 11100001b
MOV Dl,3Fh
ROL Dl,4 ; DL = F3h
70
ROR Instruction
ROR (rotate right) shifts each bit to the right
The lowest bit is copied into both the Carry
flag and into the highest bit
No bits are lost
CF
MOV AL,11110000b
ROR AL,1 ; AL = 01111000b
MOV DL,3Fh
ROR DL,4 ; DL = F3h
71
String?
72
String Instruction
Basics
Source DS:SI, Destination ES:DI
75
Mnemo- meaning format Operation
Nic
SCAS Scan string SCASB/ Set flags as per
AX – ES:DI SCASW (AL or AX) - ((ES)0+(DI))
(DI) (DI) ± 1 or 2
76
(4). String Manipulation
Instructions
(1). REP
80
Conditional Jump instructions
81
Conditional Jump Instructions
Mnemonic : Jcc
Meaning : Conditional Jump
Format : Jcc operand
Operation : If condition is true jump to the address specified by operand.
Otherwise the next instruction is executed.
Flags affected : None
82
TYPES
JB Below CF=1
JC Carry CF=1
JE Equal ZF=1
84
Mnemonic meaning condition
JNLE Not Less nor Equal ZF = 0 and SF = OF
JNO Not Overflow OF = 0
JNP Not Parity PF = 0
JNZ Not Zero ZF = 0
JNS Not Sign SF = 0
JO Overflow OF = 1
JP Parity PF = 1
JPE Parity Even PF = 1
JPO Parity Odd PF = 0
JS Sign SF = 1
JZ Zero ZF = 1
85
Jumps Based on a single flag
JZ r8 ;Jump if zero flag set to 1 (Jump if result is zero)
JNZ r8 ;Jump if Not Zero (Z flag = 0 i.e. result is nonzero)
JS r8 ;Jump if Sign flag set to 1 (result is negative)
JNS r8 ;Jump if Not Sign (result is positive)
86
JZ r8 ; JE (Jump if Equal) also means same.
JNZ r8 ; JNE (Jump if Not Equal) also means same.
JC r8 ;JB (Jump if below) and JNAE (Jump if Not
Above or Equal) also mean same.
87
(6). Flag Manipulation
Instructions
(1). CMC
Also known as Complement Carry Flag.
It inverts contents of carry flag.
if CF = 1 then CF will be = 0.
if CF = 0 then CF will be = 1.
E.g. CMC
88
(6). Flag Manipulation
Instructions
(2). STC
Also known as Set Carry Flag.
It makes carry flag in set condition.
After execution CF = 1.
E.g. STC
89
(6). Flag Manipulation
Instructions
(3). CLI
Also known as Clear Interrupt Flag.
It makes interrupt flag in reset condition.
After execution IF = 0.
E.g. CLI
90
(6). Flag Manipulation
Instructions
(4). CLD
Also known as Clear Direction Flag.
It makes direction flag in reset condition.
After execution DF = 0.
E.g. CLD
91
(7). Machine Control
Instructions
(1). HLT
Also known as Halt
It makes the processor to be in stable
E.g. HLT
92
(7). Machine Control
Instructions
(2). NOP
Also known as No Operation.
It tells about further there will be no
operation to be performed.
E.g. NOP
93