0% found this document useful (0 votes)
15 views97 pages

Instruction Set 8086slide

The 8086 microprocessor supports six types of instructions: Data Transfer, Arithmetic, Logical, String Manipulation, Process Control, and Control Transfer. Data Transfer instructions include MOV, XCHG, PUSH, POP, IN, OUT, XLAT, LEA, and LDS, which facilitate the movement of data between registers, memory, and I/O ports. Arithmetic instructions such as ADD, SUB, INC, DEC, CMP, DAA, DAS, NEG, MUL, IMUL, DIV, and IDIV perform various mathematical operations on data.

Uploaded by

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

Instruction Set 8086slide

The 8086 microprocessor supports six types of instructions: Data Transfer, Arithmetic, Logical, String Manipulation, Process Control, and Control Transfer. Data Transfer instructions include MOV, XCHG, PUSH, POP, IN, OUT, XLAT, LEA, and LDS, which facilitate the movement of data between registers, memory, and I/O ports. Arithmetic instructions such as ADD, SUB, INC, DEC, CMP, DAA, DAS, NEG, MUL, IMUL, DIV, and IDIV perform various mathematical operations on data.

Uploaded by

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

INSTRUCTION SET of

8086
8086
Microprocessor Instruction Set

8086 supports 6 types of instructions.

1. Data Transfer Instructions

2. Arithmetic Instructions

3. Logical Instructions

4. String manipulation Instructions

5. Process Control Instructions

6. Control Transfer Instructions

2
8086
Microprocessor Instruction Set

1. Data Transfer Instructions


Instructions that are used to transfer data/ address in to
registers, memory locations and I/O ports.

Generally involve two operands: Source operand and


Destination operand of the same size.

Source: Register or a memory location or an immediate


data
Destination : Register or a memory location.

The size should be a either a byte or a word.

A 8-bit data can only be moved to 8-bit register/ memory


and a 16-bit data can be moved to 16-bit register/
memory.
3
1. Data Transfer Instructions

• MOV Destination, Source


• XCHG Destination, Source
• PUSH Source (16 bit)
• POP Destination(16 Bit)
• IN Accumulator, Port
• OUT Port, Accumulator
• XLAT – Translate a byte in AL
• LEA 16 bit register, Source
• LDS 16 bit Register, Memory address of the first
word
• LAHF
• SAHF
• PUSHF
• POPF
4
Data Transfer

• MOV Destination, Source


• Operation:
• Destination  Source
• The source can be a register, a memory
location or an immediate number.
• The destination can be a register or a
memory location.
• The source and destination cannot both be
memory locations

5
• MOV CX, 037AH ; Put immediate number 037AH to CX
• MOV BL, [437AH] ; Copy byte in DS at offset 437AH to BL
• MOV AX, BX ; Copy content of register BX to AX
• MOV DL, [BX] ; Copy byte from memory at [BX] to DL
• MOV DS, BX ; Copy word from BX to DS register

• MOV DS, 1234H


• Immediate data can not move to segment register
• MOV [BX] ,[2500H]
• The source and destination cannot both be memory
locations
• CS register may not be altered by a MOV
instruction
6
• XCHG Destination, Source

• The XCHG instruction exchanges the


content of a register with the content
of another register or with the
content of memory location(s).
• It cannot directly exchange the
content of two memory locations
• The segment registers cannot be
used in this instruction.

7
• XCHG AX, DX
• Exchange word in AX with word in DX

• XCHG BL, CH
• Exchange byte in BL with byte in CH

• XCHG AL, PRICES [BX]


• Exchange byte in AL with byte in memory

8
STACK RELATED INSTRUCTIONS

• PUSH Source (16 bit)


• The PUSH instruction decrements the
stack pointer by 2 and copies a word
from a specified source to the
location in the stack segment to
which the stack pointer points.
• The source of the word can be
general-purpose register, segment
register, or memory

9
• Operation
• SP  SP – 2
• SS:[SP]  LSB of source
• SS:[SP+1]  MSB of source
• Examples
• PUSH BX
• Decrement SP by 2, copy BX to stack.
• PUSH DS
• Decrement SP by 2, copy DS to stack.
• PUSH BL Illegal; must push a word

10
11
• POP Destination(16 Bit)
• The POP instruction copies a word
from the stack location pointed by the
stack pointer to a destination specified
in the instruction

• Operation
• LSB of destination  SS:[SP]
• MSB od destination  SS:[SP+1]
• SP  SP+2

12
13
• Examples

• POP DX
• Copy a word from top of stack to DX;
increment SP by 2
• POP DS
• Copy a word from top of stack to DS;
increment SP by 2
• POP [8000H]
• Copy a word from top of stack to
memory
14
• PUSHF
• (PUSH FLAG REGISTER TO STACK)

• POPF
• (POP WORD FROM TOP OF STACK TO
FLAG REGISTER)

15
INPUT-OUTPUT INSTRUCTIONS

• IN Accumulator, Port

• IN instruction copies data from a port


to the AL or AX register

• IN instruction has two possible


formats, fixed port and variable port.
For fixed port type, the 8-bit address
of a port is specified directly in the
instruction
16
• Operation:
• AL  [Port] for byte
• AL  [Port] and AH  [Port+1] for word
• Fixed Port type (8 bit port address)
• Port address is directly specified in the
instruction
• Examples
• IN AL,80H
• Input a byte from port whose address is 80H
• IN AX,80H
• Input a word from port whose address is
80H
17
• Variable Port type
• The 16 bit port address is specified in DX
register only
• Examples
• MOV DX ,8000H
• IN AL,DX
• Input a byte from port whose address is in
DX to AL
• IN AX,DX
• Input a word from port whose address is in
DX to AX

18
• OUT Port, Accumulator
• The OUT instruction copies a byte from AL or
a word from AX to the specified port.
• Operation:

• [Port]  AL for byte

• [Port]  AL and [Port+1]AH for word

19
• Examples
• In fixed port type

• OUT 80H,AL
• Copy the contents of AL to port 80H

• OUT 80H,AX
• Copy the contents of AX to port 80H

20
• Variable port type
• MOV DX,8000H
• Intialise DX with 16 bit port address

• OUT DX,AL
• Copy the contents of AL to port

• OUT DX,AX
• Copy the contents of AX to port

21
• XLAT – Translate a byte in AL
• The instruction replaces a byte in AL register
with a byte pointed by BX in a lookup table in
the memory.
• The XLAT instruction adds the byte in AL to
the offset of the start of the table in BX.
• It then copies the byte from the address pointed
to by (BX + AL) back into AL.
• Operation:
• AL  DS:[BX + AL]

22
23
• LEA 16 bit register, Source
• (Load Effective Address)
• This instruction determines the offset of the variable
or memory location named as the source and puts
this offset in the indicated 16-bit register.

• Loads the destination register with


effective address of the source

• Used to access array elements by its


base address
24
• Examples

• LEA BX, ARRAY


• Load BX with the offset of variable ARRAY

• LEA SI,LIST
• Load SI with the offset of variable LIST

25
26
27
• LDS 16 bit Register, Memory address
of the first word
• The word from two memory locations is
copied into the specified register and

• the word from the next two memory


locations is copied into the DS registers.
• Operation:
• 16 bit register  [memory address]
• DS [memory address +2]

28
• Example
• LDS BX, [4326]
• Copy content of memory location
4326H to BL,content of 4327H to BH

Copy content of memory location


4328H and 4329H in to DS register.

29
30
• Example
• LES BX, [4326]
• Copy content of memory location
4326H to BL,content of 4327H to BH

Copy content of memory location


4328H and 4329H in to ES register.

31
• LAHF (COPY LOW BYTE OF FLAG REGISTER
TO AH REGISTER)
• The LAHF instruction copies the low-byte of
the 8086 flag register to AH register

• SAHF (COPY AH REGISTER TO LOW BYTE OF


FLAG REGISTER)
• The SAHF instruction replaces the low-byte
of the 8086 flag register with a byte from
the AH register.

32
ARITHMETIC INSTRUCTIONS

• ADD Destination, Source


• Operation:
• Destination  Source + Destination
• ADD AL,25H
• ADD AX,BX
• ADD AL,[SI]
• ADC Destination, Source
• Operation
• Destination  Source + Destination + CF

33
ARITHMETIC INSTRUCTIONS

• SUB Destination, Source


• Operation:
• Destination  Destination - Source
• SUB AL,25H
• SUB AX,BX
• SUB AL,[SI]
• SBB Destination, Source
• Operation
• Destination  Destination –Source - CF

34
• INC Destination
• The INC instruction adds 1 to a specified
register or to a memory location
• INC BL
• Add 1 to contains of BL register
• INC CX
• Add 1 to contains of CX register
• INC BYTE PTR [BX]
• Increment byte in data segment at offset
contained in BX.
• INC WORD PTR [BX]
• Increment word in data segment at offset
contained in BX. 35
• DEC Destination
• This instruction subtracts 1 from the
destination word or byte. The destination
can be a register or a memory location.
• DEC CL
• Subtract 1 from content of CL register
• DEC BP
• Subtract 1 from content of BP register
• DEC BYTE PTR [BX]
• Subtract 1 from byte at offset [BX] in DS.
• DEC WORD PTR [BX]
• Subtract 1 from a word at offset [BX] in DS.

36
• CMP Destination, Source
• This instruction compares a byte / word in the
specified source with a byte / word in the
specified destination.

• The source can be an immediate number, a


register, or a memory location.

• The destination can be a register or a memory


location.

• However, the source and the destination cannot


both be memory locations.
37
• The comparison is actually done by
subtracting the source byte or word
from the destination byte or word

• The source and the destination are not


changed, but the flags are set to
indicate the results of the comparison.

38
• Operation
• a)If destination > source then
• CF=0, ZF=0, SF=0

• b)If destination < source then


• CF=1, ZF=0, SF=1

• c) If destination = source then


• CF=0, ZF=1, SF=0

39
• DAA (Decimal Adjust Accumulator)
• (DECIMAL ADJUST AFTER BCD ADDITION)

• This instruction is used to convert the result of the


addition of two packed BCD numbers to a valid BCD
number

• DAA works on only AL register

• So DAA instruction must be used after the


ADD/ADC instruction

40
• Operation
• a)If lower nibble of AL>9 or AF=1
• then AL=AL+06

• b)If higher nibble of AL>9 or CF=1


• then AL=AL+60

• c)If both above condition are satisfied


• Then AL=AL+66

41
• Examples:

• Let AL = 59 BCD, and BL = 35 BCD


• ADD AL, BL ; AL = 8EH; lower nibble > 9, add 06H to AL
• DAA ; AL = 94 BCD, CF = 0

• Let AL = 88 BCD, and BL = 49 BCD


• ADD AL, BL ;AL = D1H; AF = 1, add 06H to AL
• DAA ;AL = D7H; upper nibble > 9, add 60H to AL
;AL = 37 BCD, CF = 1

42
• DAS (DECIMAL ADJUST AFTER BCD SUBTRACTION)
• This instruction is used after subtracting one
packed BCD number from another packed BCD
number, to make sure the result is correct packed
BCD
• Operation:
a)If lower nibble of AL>9 or AF=1
then AL=AL-06
b)If higher nibble of AL>9 or CF=1
then AL=AL-60
c)If both above condition are satisfied
then AL=AL-66

43
• Examples
• Let AL = 86 BCD, and BH = 57 BCD
• SUB AL,BL ; AL = 2FH; lower nibble > 9, subtract 06H
• from AL

• DAS ;AL = 29 BCD, CF = 0

• Let AL = 49 BCD, and BH = 72 BCD


• SUB AL, BH ;AL = D7H; upper nibble > 9, subtract 60H
• from AL
• DAS ; AL = 77 BCD, CF = 1 (borrow is needed)

44
• NEG Destination
• This instruction replaces the number in a
destination with its 2’s complement.
• The destination can be a register or a
memory location
• NEG AL ;Replace number in AL with its 2’s complement
• NEG BX ; Replace number in BX with its 2’complement

• NEG BYTE PTR [BX]


;Replace byte at offset BX in DS with its 2’s complement

45
• MUL Source
• This instruction multiplies an unsigned byte in
some source with an unsigned byte in AL
register
• or an unsigned word in some source with an
unsigned word in AX register
• The source can be a register or a memory
location.

46
• Operation:
• a)If source is byte then
• AX  AL* Unsigned 8 bit source
b)If source is word then
• DX:AX AX* Unsigned 16 bit source
• MUL BH ;Multiply AL with BH; result in AX
MUL CX ;Multiply AX with CX; result high
word in DX, low word in AX
MUL BYTE PTR [BX] ;Multiply AL with byte
in DS pointed by [BX]

48
• IMUL Source
• This instruction multiplies a signed byte from
source with a signed byte in AL
• or a signed word from some source with a
signed word in AX.
• The source can be a register or a memory
location
• IMUL BH

49
• DIV Source
• This instruction is used to divide an
unsigned word by a byte
• or to divide an unsigned double word
(32 bits) by a word.

50
• Operation:
• a)If source is Byte then,
• AL  AX/ unsigned 8 bit source (Quotient)
• AH  AX MOD unsigned 8 bit source
(Remainder)
b)If source is Word then,
AX  DX:AX/unsigned 16 bit source (Q)
DX  DX:AX MOD unsigned 16bit source(R)

51
• Examples
• DIV BL
• Divide word in AX by byte in BL; Quotient in
AL, Remainder in AH

• DIV CX
• Divide double word in DX and AX by word in
CX;
• Quotient in AX, and Remainder in DX.
• IDIV Source
• This instruction is used to divide a signed word
by a signed byte, or to divide a signed double
word by a signed word.

• IDIV BL ;Signed word in AX/signed byte in BL

• IDIV BYTE PTR [BX]


• CBW (CONVERT SIGNED BYTE TO SIGNED WORD)
• This instruction copies the sign bit of the byte in AL to all the
bits in AH.
• AH is then said to be the sign extension of AL

• Let AX = 00000000 10011011 (–155 decimal)


• CBW
• Convert signed byte in AL to signed word in AX
• AX = 11111111 10011011 (–155 decimal)
• CWD (CONVERT SIGNED WORD TO SIGNED DOUBLE
WORD)
• This instruction copies the sign bit of a word in AX to all the bits
of the DX register.
• In other words, it extends the sign of AX into all bits of DX.

• Let DX = 00000000 00000000, and


AX = 11110000 11000111
• CWD
• Convert signed word in AX to signed double
word in DX:AX
• DX = 11111111 11111111
• AX = 11110000 11000111
LOGICAL INSTRUCTIONS
• AND Destination, Source
• This instruction ANDs each bit in a source byte or
word with the same numbered bit in a destination
byte or word.
• The result is put in the specified destination.
• The source can be an immediate number, the content
of a register, or the content of a memory location.
• The destination can be a register or a memory
location
• The source and the destination cannot both be
memory locations.
• OR Destination, Source
• This instruction ORs each bit in a source byte or
word with the same numbered bit in a
destination byte or word.
• The result is put in the specified destination.

• Example: OR AX,BX
• XOR Destination, Source
• This instruction Exclusive-ORs each bit in a
source byte or word with the same numbered bit
in a destination byte or word.
• The result is put in the specified destination

• NOT Destination
• The NOT instruction inverts each bit (forms the
1’s complement) of a byte or word in the
specified destination.
• The destination can be a register or a memory
location
• TEST Destination, Source
• This instruction ANDs the byte / word in
the specified source with the byte / word in
the specified destination.
• Flags are updated, but neither operand is
changed.
• TEST AL, BH ;AND BH with AL. No result
stored; Update PF, SF, ZF.
• TEST CX, 0001H AND CX with immediate
number 0001H;
• No result stored; Update PF, SF, ZF
SHIFT and ROTATE Instructions
• SAL Destination, Count
• SHL Destination, Count
• SAL and SHL are two mnemonics for the same
instruction.
• This instruction shifts each bit in the specified
destination some number of bit positions to the left.
• As a bit is shifted out of the LSB operation, a 0 is
put in the LSB position.
• The MSB will be shifted into CF.
• SAL BX, 1 ;Shift word in BX 1 bit position left, 0 in LSB
• MOV CL, 02h ;Load desired number of shifts in CL
• SAL BP, CL ;Shift word in BP left CL bit positions, 0 in LSBs
Branch instructions
Control Transfer Instructions

• Conditional Jumps
• Short Jump
– All conditional jumps are short jump
– The address of the target must be within –128 to +127 bytes
of the IP
Control Transfer Instructions
• NEAR – When control transferred to a memory location
within the current code segment

• FAR – When control is transferred outside the current code


segment

• CS:IP – This register always points to the address of the next


instruction to be executed.
• In a NEAR jump, IP is updated, CS remains the same
• In a FAR jump, both CS and IP are updated
• Jump Instruction

• JMP (Jump) unconditionally transfers


control to the target location
• JMP is a one-way transfer of
execution
• it does not save a return address on
the stack

80
• If target of JMP is in the same code
segment only IP to be changed to transfer
control to the target location
• Such jump is called as intra-segment jump
or near jump
• If target of jump is in different code
Segment, then IP & CS will be changed
• Such a jump is called as far or inter-
segment jump
• Examples
• JMP Down
• JMP FAR PTR SKIP

81
8086
Microprocessor Instruction Set

Control Transfer Instructions

 8086 conditional branch instructions affecting individual


flags
Mnemonics Explanation

JC disp8 Jump if CF = 1

JNC disp8 Jump if CF = 0

JP disp8 Jump if PF = 1

JNP disp8 Jump if PF = 0

JO disp8 Jump if OF = 1

JNO disp8 Jump if OF = 0

JS disp8 Jump if SF = 1

JNS disp8 Jump if SF = 0

JZ disp8 Jump if result is zero, i.e, Z = 1

JNZ disp8 Jump if result is not zero, i.e, Z = 1

82
Unconditional control Transfer

• CALL a procedure
• Used to call a procedure and save
their return address to the stack.
• The CALL instruction is used to
transfer execution to a subprogram
or a procedure.
• There two basic type of calls near
and far.

83
84
• Operation:

• 1.If NEAR CALL then


• SP  SP-2
• Save IP on stack
• IP  address of procedure

85
• If FAR CALL then
• SP  SP-2
• Save CS on stack
• CS  New segment base address of
• the called procedure
• SP  SP-2
• Save IP on stack
• IP  New offset address of the
• called procedure

86
• RET (RETURN EXECUTION FROM PROCEDURE TO
CALLING PROGRAM)
• The RET instruction will return execution from a
procedure to the next instruction after the CALL
instruction in the calling program
• Operation:
• 1)For NEAR Return
• IP  contents of top of stack
• SP  SP+2
• 2)For FAR Return
• IP  contents of top of stack
• SP  SP+2
• CS  contents of top of stack
• SP  SP+2
87
Iteration Control Instructions
• LOOP (JUMP TO SPECIFIED LABEL IF CX ≠ 0
AFTER AUTO DECREMENT)
• This instruction is used to repeat a series of
instructions some number of times.
• Each time the LOOP instruction executes,
CX is automatically decremented by 1.
• If CX is not 0, execution will jump to a
destination specified by a label in the
instruction.
• If CX = 0 after the auto decrement,
execution will simply go on to the next
instruction after LOOP.
88
89
90
• Example:
• LEA SI,ARRAY
• MOV AL,00H
• MOV CX,10H ;Counter loaded
• Up: ADD AL,[SI]
• INC SI
• LOOP UP DEC CX
JNZ UP

91
• LOOPE / LOOPZ (LOOP WHILE CX ≠
0 AND ZF = 1)
• This instruction is used to repeat a group of
instructions some number of times, or until
the zero flag becomes 0.
• The number of times the instruction
sequence is to be repeated is loaded into
CX.

92
93
• Each time the LOOP instruction
executes, CX is automatically
decremented by 1.
• If CX ≠ 0 and ZF = 1, execution will
jump to a destination specified by a
label in the instruction.
• If CX = 0, execution simply go on the
next instruction after LOOPE / LOOPZ.
• In other words, the two ways to exit
the loop are CX = 0 or ZF = 0.

94
• LOOPNE / LOOPNZ (LOOP WHILE CX ≠ 0
AND ZF = 0)
• This instruction is used to repeat a group of
instructions some number of times, or until
the zero flag becomes a 1.

• Each time the LOOPNE / LOOPNZ instruction


executes, CX is automatically decremented
by 1.

• If CX ≠ 0 and ZF = 0, execution will jump to


a destination specified by a label in the
instruction.
95
• If CX = 0, after the auto decrement or
if ZF = 1, execution simply go on the
next instruction after
LOOPNE / LOOPNZ.

• In other words, the two ways to exit


the loop are CX = 0 or ZF = 1.

96
97

You might also like