0% found this document useful (0 votes)
83 views27 pages

Module - 1 8086 Instruction Sets

The document describes the various instruction sets of the 8086 microprocessor. It discusses 8 categories of instructions: data transfer, arithmetic, logical, flags controlling, branching, I/O, stack, and string instructions. For some of the major instruction types like data transfer, arithmetic, and logical instructions, examples of operations are provided along with example code snippets. The purpose of the document is to provide an overview of the different instruction sets available in the 8086 and examples of how to use some common instructions through example programs.

Uploaded by

You know Me
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views27 pages

Module - 1 8086 Instruction Sets

The document describes the various instruction sets of the 8086 microprocessor. It discusses 8 categories of instructions: data transfer, arithmetic, logical, flags controlling, branching, I/O, stack, and string instructions. For some of the major instruction types like data transfer, arithmetic, and logical instructions, examples of operations are provided along with example code snippets. The purpose of the document is to provide an overview of the different instruction sets available in the 8086 and examples of how to use some common instructions through example programs.

Uploaded by

You know Me
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 27

Module – 1

8086 Instruction sets

1
Instruction sets of 8086

1. Data Transfer instructions


2. Arithmetic Instructions
3. Logical Instructions
4. Flags controlling Instructions
5. Branching instructions
6. I/O instructions
7. Stack instructions
8. String Instructions

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

? 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.
MOV AX, [BX]
ADD [SI], AX
MOV AX, [BX+2]
ADC [SI+2], AX
MOV AX, [BX+4]
ADC [SI+4], AX
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.
? 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
MOV DX, AX
HLT

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.

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


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
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.
 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.
 ? 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.

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

 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. 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

 STC – Set Carry Flag.


 STD – Set Direction flag.
 STI – Set Interrupt flag.
 CLC – Clear carry flag.
 CLI – Clear Interrupt flag.
 CMC- Complement the Carry Flag.

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,

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


 JNA / JBE
 JB / JNAE
 JNB / JAE

 JG / JNLE – conditional jump for signed numbers.


 JNG/ JLE
 JL/ JNGE
 JNL/ JGE

22
Branching Instructions

 CALL operand – unconditional CALL.


 Intra segment CALL
 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.
 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.
 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

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


 PUSH AX
 [AX]  3020h
 SS = 7000h
 SP=ST=0130h
 AL  70130 and AH  70131
 PUSHF – Push flag register content to Stack.
 POP D(16bit) –
 POP AX
 [70130]  AL
 [70131]  AH
 POPF – Change the flag register content.
26
String Instructions

Seminar 1

27

You might also like