You are on page 1of 27

Module – 1

8086 Instruction sets

1
Instruction sets of 8086

1. Data Transfer instructions


Arithmetic Instructions

VIT University
Jasmin T Jose Asst. professor
2.
3. Logical Instructions
4. Flags controlling Instructions
5. Branching instructions
6. I/O instructions
7. Stack instructions
String Instructions

SCSE,
8.

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.

VIT University
Jasmin T Jose Asst. professor
➢ 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

SCSE,
➢ 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

VIT University
Jasmin T Jose Asst. professor
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]

SCSE,
➢ 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

VIT University
Jasmin T Jose Asst. professor
Reg Mem
Mem Reg
Reg/Mem data
➢ ADC D, S- Add D and S with carry

SCSE,
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.

VIT University
Jasmin T Jose Asst. professor
➢ ADD BX, DI
MOV ES:[2000H], BX
ADC AX, SI
MOV ES:[2002H],AX
MOV AL, 00H

SCSE,
ADC AL,AL
MOV ES:[2004],AL
HLT
6
Arithmetic Instructions

? Write a program to perform the addition X + Y, where X and Y are 48bit


numbers present in memory address from DS: BX and DS: SI. Store the
result in memory address from DS: SI.

VIT University
Jasmin T Jose Asst. professor
MOV AX, [BX]
ADD [SI],AX
MOV AX, [BX+2]
ADC [SI+2],AX
MOV AX, [BX+4]
ADC [SI+4],AX

SCSE,
MOV AL, 00H
ADC AL,AL
MOV [SI+6],AL
HLT
7
Arithmetic Instructions
➢ DAA – Decimal adjust after addition.
➢ Only 8bit addition is possible.
➢ One data should be in AL register.

VIT University
Jasmin T Jose Asst. professor
? Write a program to add two BCD numbers 45 and 57, store
the result and carry in register DL and DH respectively.
MOV AL, 45H
ADD AL, 57H
DAA
MOV AH, 00H
ADC AH,AH

SCSE,
MOV DX,AX
HLT

8
Arithmetic Instructions
➢ AAA – ASCII adjust after addition.
➢ Only 8bit addition is possible.
➢ One data should be in AL register.

VIT University
Jasmin T Jose Asst. professor
➢ 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

SCSE,
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.

VIT University
Jasmin T Jose Asst. professor
➢ 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.

SCSE,
10
Arithmetic Instructions
➢ DAS – Decimal adjust after subtraction.
➢ Only 8bit addition is possible.
➢ One data should be in AL register.

VIT University
Jasmin T Jose Asst. professor
➢ 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.

SCSE,
➢ 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

VIT University
Jasmin T Jose Asst. professor
➢ 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.

SCSE,
➢ 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.

VIT University
Jasmin T Jose Asst. professor
➢ 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).

SCSE,
➢ 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,

VIT University
Jasmin T Jose Asst. professor
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.

SCSE,
➢ 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.

VIT University
Jasmin T Jose Asst. professor
➢ 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.

? Write a program to perform Division 8573h/156Eh. Store the result in

SCSE,
memory DS:DI.

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

VIT University
Jasmin T Jose Asst. professor
complement form.
➢ Result also signed number in 2’s complement form.

➢ IDIV S – 16/8 bit division.


➢ AX/S → Quotient is obtained in AL and remainder in AH.
➢ IDIV S – 32/16 bit Division.

SCSE,
➢ DX AX/S → Quotient is obtained in AX and remainder in DX.
➢ AAD - ASCII adjust before division.

16
Logical Instructions

➢ AND D, S – After AND operation, result will be stored in destination.


➢ TEST D, S - After AND operation, result will be stored in ALU. PF, Zf
and SF Flags are affected.

VIT University
Jasmin T Jose Asst. professor
➢ ? Test the value of D3 bit of register CH without affecting other bits.
➢ OR D, S – Result will be stored in destination.
➢ ? Set two MSBs and two LSBs of register AL without affecting other bits.
➢ XOR D, S – Result will be stored in destination.
➢ ? What is the result of XOR AH,E0h .
➢ NOT D - D cannot be an immediate data.

SCSE,
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.

VIT University
Jasmin T Jose Asst. professor
➢ 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

SCSE,
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

➢ LSB will be copied to CF, CF will be moved to MSB.


Logical Instructions

➢ SHIFTING INSTRUCTIONS
➢ SAL/SHL D, count – Shift Arithmetic Left/ Shift Logical Left destination.

VIT University
Jasmin T Jose Asst. professor
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.

SCSE,
➢ 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

➢ STC – Set Carry Flag.


➢ STD – Set Direction flag.

VIT University
Jasmin T Jose Asst. professor
➢ STI – Set Interrupt flag.
➢ CLC – Clear carry flag.
➢ CLI – Clear Interrupt flag.
➢ CMC- Complement the Carry Flag.

SCSE,
20
Branching Instructions

➢ A new 16bit address is transferred to IP, instead of reading the


next instruction code in sequence.
➢ Intrasegment branching
➢ Intersegment branching

VIT University
Jasmin T Jose Asst. professor
➢ 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

SCSE,
➢ 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,

➢ JA / JNBE operand – conditional jump for unsigned numbers.

VIT University
Jasmin T Jose Asst. professor
➢ JNA / JBE
➢ JB / JNAE
➢ JNB / JAE

➢ JG / JNLE – conditional jump for signed numbers.


➢ JNG/ JLE

SCSE,
➢ JL/ JNGE
➢ JNL/ JGE

22
Branching Instructions

➢ CALL operand – unconditional CALL.


➢ Intra segment CALL

VIT University
Jasmin T Jose Asst. professor
➢ Inter segment CALL
➢ Short/Near CALL – IP alone will be changed
➢ Far CALLs- IP and CS will be changed
➢ Single subroutine
➢ Nested CALL.
➢ RET – returns back from sub program to main program, next instruction
after the CALL instruction.

SCSE,
➢ If intra-segment subroutine, then POP IP.
➢ If inter-segment subroutine, POP IP, POP CS
➢ RET DISPLACEMENT- Stack Top = [SP] + DISP
23
Machine Control Instructions

➢ NOP –
➢ Used in delay program to waste the time of MP.

VIT University
Jasmin T Jose Asst. professor
➢ 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.

SCSE,
➢ 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.

VIT University
Jasmin T Jose Asst. professor
➢ 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

SCSE,
➢ 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

➢ PUSH S(16bit) – S can be Reg./ Seg.reg/ Memory


➢ PUSH AX
➢ [AX] → 3020h

VIT University
Jasmin T Jose Asst. professor
➢ SS = 7000h
➢ SP=ST=0130h
➢ AL → 70130 and AH → 70131
➢ PUSHF – Push flag register content to Stack.
➢ POP D(16bit) –
➢ POP AX

SCSE,
➢ [70130] → AL
➢ [70131] → AH
➢ POPF – Change the flag register content.
26
Jasmin T Jose Asst. professor SCSE,
VIT University
27
1
➢ Seminar
String Instructions

You might also like