Module - 1 8086 Instruction Sets
Module - 1 8086 Instruction Sets
1
Instruction sets of 8086
2
Data transfer Instructions
• Transferring 8/16 bit data from source to destination.
• Size of the source and destination should be same.
MOV D, S- Move source data to destination.
Possible combination of source and destination is,
Source Destination
Register Register
Register Memory
Memory Register
Data Reg/mem
Seg. Reg Reg/Mem
Reg/Mem Seg reg except CS
LAHF - Load AH with 8 LSBs of Flag register.
SAHF - Store AH into 8 LSBs of Flag register.
3
Data transfer Instructions
XCHG D, S- Exchange the content of source and destination.
Possible combination of source and destination is,
Source Destination
Register Register
Register Memory
Eg. XCHG AL,BL XCHG CX, [7800h]
XCHG BX, 8000h not possible.
LDS RX, Mem – Load DS and the given Register with memory
content.
Eg. LDS SI, ES:[BX]
LES RX, Mem – Load ES and given register with memory content.
LEA RX, EA source - Load EA of memory into given register.
4
Arithmetic Instructions- Addition
ADD D, S –
Possible combinations are,
Destination Source
Reg Reg
Reg Mem
Mem Reg
Reg/Mem data
ADC D, S- Add D and S with carry
5
Arithmetic Instructions
? Write a program to add two 32 bit numbers present in registers
AX-BX and SI-DI. Store the result and carry in memory from
ES: 2000h.
ADD BX, DI
MOV ES:[2000H],
BX
ADC AX, SI
MOV ES:[2002H],
AX
MOV AL, 00H
ADC AL,AL
MOV ES:[2004], AL
6
HLT
Arithmetic Instructions
8
Arithmetic Instructions
AAA – ASCII adjust after addition.
Only 8bit addition is possible.
One data should be in AL register.
Make AH as 00.
After addition,
If LSB nibble of AL > 9 or AC flag is 1 then
Add 6 to LSB nibble.
MSB nibble of AL = 0.
If AC=1 then AH = 01
9
Arithmetic Instructions -Subtraction
SUB D, S – Subtract source data from destination data.
Result will be in Destination .
SBB D, S- Subtract source data with borrow from destination data.
D = D - S – CF
? Write a program to subtract 32 bit number present in register AX-
BX from 32 bit number present in register CX-DX. Store the result
in register SI-DI.
10
Arithmetic Instructions
DAS – Decimal adjust after subtraction.
Only 8bit addition is possible.
One data should be in AL register.
After subtraction,
If AC = 1, subtract 6 from LSB
If CF = 1, subtract 6 from MSB
? Write a program to perform the subtraction of two decimal
numbers 73D and 28D, store the result in BCD format in
register AH.
AAS – ASCII adjust after subtraction.
Only 8bit addition is possible.
One data should be in AL register.
11
Arithmetic Instructions
CMP D, S – Compare source data and destination data.
Flags will be affected.
If D > S, then CF=0 and ZF=0
If D < S, then CF=1 and ZF=0
If D = S, then CF=0 and ZF=1
INC D – Increment the content of destination. D R/M, not data
DEC D – Decrement the content of destination. D R/M, not data
NEG D - Negate the content of destination. D R/M, not data
2’s complement of the destination data.
Only 8bit is possible.
CBW – Convert the Sign Byte into Sign Word. Result will be in AX. Sign
bit will be added to the AH register.
CWD – Convert sign word into sign Double Word. Result will be in DX-
12
AX. Sign bit will be added to the DX register.
Arithmetic Instructions- Multiplication
Unsigned number
Multiplication of source data with Accumulator in equal length.
Source can be register or memory, not data.
MUL S – 8 bit multiplication. Result will be 16 bit.
AX = AL * S
If AH = 00h, then OF=CF=0
Else OF=CF=1
MUL S – 16 bit multiplication. Result will be 32bit.
DX AX = AX * S(16bit).
If DX = 0000h, then OF=CF=0
Else OF=CF=1
? Write a program to perform multiplication of 1Dh and 156Eh. Store the
result in memory DS:SI.
13
Arithmetic Instructions- Multiplication
Signed number
IMUL S – 8 bit multiplication. Result will be 16 bit.
AX = AL * S(8bit).
If signed bit of AL is 0/1 and the number in AH is 00/FF
respectively, then the AH of the result is neglected.
In such case, OF=CF=0.
Else OF=CF=1, total AX is the result.
IMUL S – 16 bit multiplication. Result will be 32bit.
If signed bit of AX is 0/1 and the number in DX is 0000/FFFF
respectively, then the DX of the result is neglected.
In such case, OF=CF=0.
Else OF=CF=1, total DX AX is the result.
? Write a program to perform multiplication of 15h and -76h. Store the
result in BX.
14
:Use NEG instruction
AAM - ASCII adjust after multiplication.
Arithmetic Instructions- Division
Unsigned number
Default source( Dividend) is Accumulator. Divisor will be in any
register or memory.
Source can be register or memory, not data.
DIV S – 16/8 bit division.
AX/S Quotient is obtained in AL and remainder in AH.
DIV S – 32/16 bit Division.
DX AX/S Quotient is obtained in AX and remainder in DX.
15
Arithmetic Instructions- Division
Signed number
Default source( Dividend) is Accumulator. Divisor will be in any
register or memory.
Both Dividend and divisor should be signed numbers, and in 2’s
complement form.
Result also signed number in 2’s complement form.
16
Logical Instructions
17
Logical Instructions
ROTATING INSTRUCTIONS
ROL D, count – Rotate left destination without carry.
MSB will be copied to CF and LSB. If the count is greater than 1,
then it should be stored in CL. Then use CL as count.
MOV CL, 03h
ROL BP, CL
RCL D, count - Rotate left destination with carry.
MSB will be copied to CF, CF will be moved to LSB.
ROR D, count – Rotate right destination without carry.
LSB will be copied to CF and MSB. If the count is greater than 1,
then it should be stored in CL. Then use CL as count.
MOV CL, 03h
ROR BX, CL – Result will be stored in destination.
RCR D, count – Rotate right destination with carry. 18
SHIFTING INSTRUCTIONS
SAL/SHL D, count – Shift Arithmetic Left/ Shift Logical Left
destination. MSB copied to CF. 0 copied to LSB.
Eg. Shift 03h by 2times.
SHR D, count - Shift Logical right destination.
LSB will be copied to CF. 0 copied to MSB.
Division of unsigned number, X/2n
Eg. Shift 10h by 3 times.
SAR D, count – Shift Arithmetic right destination.
LSB will be copied to CF and sign bit will be copied to MSB.
Division of signed number, +-X/2n
19
Flags controlling Instructions
20
Branching Instructions
A new 16bit address is transferred to IP, instead of reading the next
instruction code in sequence.
Intrasegment branching
Intersegment branching
Short jump, Near jump, Far jump (2 operand will be there).
JMP operand – Unconditional jump.
JC and JNC - Conditional Jump instructions
JZ/ JE
JNZ/ JNE
JP/ JPE
JNP/ JPO
JS and JNS
JO and JNO
21
JCXZ
? Write a program to find smallest number among n numbers.
Branching Instructions
Using after comparison instruction,
22
Branching Instructions
NOP –
Used in delay program to waste the time of MP.
It will take 3 clk cycles.
HLT - Stop the fetching and execution processes.
Again BIU can be activated by giving,
RESET
NMI
INTR
WAIT – wait for TEST or INTERRUPT signal.
MP will be in idle state
LOCK – Lock the BUS signal.
NO other processor can get the control of buses.
24
ESC - Pass control to the co-processor.
I/O Instructions
IN AL/AX, 8bit port add/DX –
If port address is of 8bit, it can be directly given in the instruction.
IN AL, 45h [0045] AL
IN AX, 55h [0055] AL and [0056] AH
If port address is of 16 bit, store it in DX register and use DX as source.
MOV DX, 2020h
IN AX, DX
OUT 8bit addr/DX, AL/AX –
If port address is of 8bits, it can be directly given in the instruction.
OUT 45h, AL [AL] 0045h
OUT 55h,AX [AL] 0055h and [AH] 0056h
If port address is of 16 bit, store it in DX register and use DX as source.
MOV DX, 2020h
OUT DX, AX
25
Stack Instructions
Seminar 1
27