Instruction Set
Instruction Set
2
Classification of Instruction Set
1. Arithmetic Instructions and Logical Instruction
2. Data Transfer Instructions
3. Branch and Loop Instruction
4. M/C control Instruction
5. Flag Manipulation Instructions
6. Shift and Rotate Instruction
7. String Instructions
3
2. Data Transfer Instructions
4
Data Transfer Instructions
MOV Des, Src:
It is used to copy the content of Src to Des
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, [SI]
MOV AL, BL
MOV BX, [0301 H]
5
Data Transfer Instructions
PUSH Operand:
It store the data into top of stack.
By this operation, SP decreases by 2.
(If SP: FF04H, after PUSH, SP: FF02H)
E.g.: PUSH DX
6
PUSHF:
It push the content of flag register into top of stack.
By this operation, SP decreases by 2.
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.
Increment the SP by 2.
E.g.: POP AX
POPF:
It pop the content of flag register from top of stack.
By this operation, SP increses by 2.
Data Transfer Instructions
IN Accumulator, Port Address:
It copy the data from the specified input port to accumulator
register.
IN AX, DX
11
XLAT :
The content of memory location in the DS whose offset
address formed by sum of AL and BX are moved to AL.
E.g.: (1) XLAT
AL = BX+AL
If DS= 1000H; AL=05H; BX=0400H
Then, Starting address = DS*10 = 10000
Offset AL+BX = 0405
P.A = 10405H
Data Transfer Instructions
LEA Register, Src:
It loads a 16-bit register with the offset address of the data
specified by the Src.
Address of p is loading in BX
13
Data Transfer Instructions
LDS Des, Src: Load data segment
It loads 32-bit pointer from memory source to
destination register and DS.
The word is placed in the destination register and the
segment is placed in DS.
This instruction Copies the word at the lower memory
address to the Des reg and the word at the higher
address to the segment reg i.e. DS.
E.g.: LDS BX, [0301 H]
14
Data Transfer Instructions
LES Des, Src: Load Extra Segment
It loads 32-bit pointer from memory source to
destination register and ES.
The Word 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, [0301 H]
15
Data Transfer Instructions
LAHF: Load AH register by lower 8 bits of flag
It copies the lower byte of flag register to AH.
PUSHF:
Pushes flag register to top of stack.
POPF:
Pops the stack top to flag register.
16
1. Arithmetic And Logical
Instructions
Arithmetic Instructions
ADD Des, Src:
It adds a byte to byte or a word to word and store
the result in Des.
It effects AF, CF, OF, PF, SF, ZF flags.
E.g.:
ADD AL, 74H
ADD DX, AX
ADD AX, [BX]
18
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]
19
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]
20
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]
21
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. And Flags-OF, CF
Unused bits of destination register is always filled with sign bit
22
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 (for word/byte)
DX=remainder, AX=quotient (for D-word/word)
IDIV Src:
It is a signed division instruction.
23
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.
If AL = 10001011 ; AH = 01001001
After CBW A=10001011 and AH= 11111111
24
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.
Copies the sign bit of a word in AX to all the bits of
DX.
Arithmetic Instructions
INC Src:
It increments the byte or word by one.
The operand can be a register or memory
location.
E.g.: INC AX
INC [SI]
26
Arithmetic Instructions
DEC Src:
It decrements the byte or word by one.
The operand can be a register or memory
location.
E.g.: DEC AX
DEC [SI]
27
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.
Source = destination : ZF is set
Source > destination : CF is set
Source < destination : CF is reset
28
Arithmetic Instructions
NEG Src:
It creates 2’s complement of a given
number.
That means, it changes the sign of a
number.
29
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.
E.g : MOV AL, 38 H
ADD AL, 45 H
DAA
HLT
For Subtraction : DAS (Decimal Adjust after Subtraction)
Arithmetic Instructions
AAA (ASCII Adjust after Addition):
This Instruction Can be used to convert the contents of the
AL register to unpacked BCD result
i.e. If lower nibble of AL>9 then
1. AL=AL+6 2. AH=AH+1
3. AL=AL and Higher nibble of AL is 0
E.g. Before AL =57H
Then Lower Nibble (7) <9 ; No change in AL but Higher nibble
of AL is 0 i.e. final Answer 07.
33
E.G. MOV AX, 0FH
Then AH= 00 H
AL = 0F H
Here F>9 ; So AL=AL+6 and AH=AH+1 and higher
nibble of AL is 0.
AL= F +6 = 15H i.e. 05 (as higher nibble will be 0)
AH = 00 +1 = 01H
Final AX=0105H
Other ASCII Instructions:
AAS (ASCII Adjust after Subtraction)
AAM (ASCII Adjust after Multiplication)
AAD (ASCII Adjust Before Division)
Logical Instructions
NOT Src:
It complements each bit of Src to produce 1’s
complement of the specified operand.
The operand can be a register or memory location.
e,.g NOT AX
36
Logical Instructions
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.
E.G: AND AH, 05H ; AND AH, CH 37
Bit Manipulation Instructions
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.
38
Bit Manipulation Instructions
XOR 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.
39
Bit Manipulation Instructions
TEST Des, Src: Logical Comparison
It performs bit wise logical AND operation of Des and
Src.
Src can be immediate number, and src/Des can be
register or memory location.
It is Non-Destructive And means Dest is not modified
only flags are affected.
Both operands cannot be memory locations at the same
time.
CF and OF become zero after the operation.
PF, SF and ZF are updated. 40
E.g.: (1) TEST AH, CH
AH = F0 H and CH = 9F H
Then, F0 AND CH = 1001 0000
i.e., SF = 1, PF = 1, ZF = 0
3. Branch/Program Execution Transfer
Instructions
These instructions cause change in the sequence of the
execution of instruction.
This change can be a conditional or sometimes
unconditional.
The conditions are represented by flags.
42
Branch Instructions
JMP Des:
This instruction is used for unconditional
jump from one place to another.
It will jump program control to label.
JB Jump if Below CF = 1
JC Jump if Carry CF = 1
JE Jump if Equal ZF = 1
JP Jump if Parity PF = 1
JZ Jump if Zero ZF = 1
44
Branch 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.
45
Loop 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.
E.G. Mov AX, 0H
again : INC AX
Loop again 46
4. Machine Control
Instructions
Machine Control Instructions
HLT (Halt) :- It causes the processor to enter in to the halt
state. It can be stop by INTR,NMI or RESET pin
NOP (No Opration) :- It causes the processor to enter in
to the wait state for 3 Clock cycles.
WAIT :- It causes the processor to enter in to the ideal state.
Can be stop by TEST, INTR OR NMI pin
LOCK :- This instruction prevents other processors to
take the control of shared resources. For e.g LOCK IN
AL,80H
48
5. Flag Manipulation
Instructions
Flag Manipulation Instructions
STC:
It sets the carry flag to 1.
CLC:
It clears the carry flag to 0.
CMC:
It complements the carry flag.
50
Flag Manipulation 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.
51
Flag Manipulation Instructions
STI:
It sets the Interrupt flag to 1.
CLI:
It clears the Interrupt flag to 0.
52
6. Shift And Rotate Instructions
Shift And Rotate Instructions
SHL/SAL 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. And recent bit to
the CF (Carry flag)
54
Shift And Rotate Instructions
SHR/SAR Des, Count:
It shift bits of byte or word right, by count.
It puts zero(s)(for SHL) and Sign bit (for SAL) 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. And recent bit to
the CF (Carry flag)
55
Shift And Rotate Instructions
ROL Des, Count:
It rotates bits of byte or word left, 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. And recent bit to
the CF (Carry flag)
56
Shift And Rotate Instructions
ROR Des, Count:
It rotates bits of byte or word right, 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. And recent bit to
the CF (Carry flag)
57
Shift And Rotate Instructions
RCL Des, Count:
It rotates bits of byte or word right, by count.
LSB to MSB then MSB is transferred to CF and CF 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. And recent bit to
the CF (Carry flag)
58
Shift And Rotate Instructions
RCR Des, Count:
It rotates bits of byte or word left, by count.
MSB to LSB then LSB is transferred to CF and CF 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. And recent bit to
the CF (Carry flag)
59
7. String Manipulation
Instructions
String Manipulation
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.
61
8086 Microprocessor
❑ 8086 instruction set includes instruction for string movement, comparison, scan, load and
store.
❑ String instructions end with S or SB or SW. S represents string, SB string byte and
SW string word.
❑ Offset or effective address of the source operand is stored in SI register and that of the
destination operand is stored in DI register.
62
String Manipulation
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
referred by DS:SI and destination string is in Extra
Segment referred by ES:DI.
For e.g. movs str1,str2
Movsb
Movsw
63
String Manipulation
Instructions
LODS / LODSB / LODSW:
It causes TRANSFER of byte or word from one string to
another.
In this instruction, the source string is in Data Segment
referred by DS:SI transferred to Accumulator.
For e.g. lods string
lodsb
lodsw
64
String Manipulation
Instructions
STOS / STOSB / STOSW:
It causes TRANSFER of byte or word from one string to
another.
In this instruction, the string is in Extra Segment referred by
ES:DI transferred to Accumulator.
For e.g. stos string
stosb
stosw
65
String Manipulation
Instructions
CMPS Des, Src:
It compares the string bytes or words.
SCAS String:
It scans a string.
It compares the String with byte in AL or with word in
AX.
66
String Manipulation
Instructions
REP (Repeat):
This is an instruction prefix.
It causes the repetition of the instruction until CX
becomes zero.
E.g.: REP MOVSB
It copies byte by byte contents.
67
8086 Microprocessor
String Manipulation
Instructions
REP
68
69