Instruction Set 8086slide
Instruction Set 8086slide
8086
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
3. Logical Instructions
2
8086
Microprocessor Instruction Set
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
7
• XCHG AX, DX
• Exchange word in AX with word in DX
• XCHG BL, CH
• Exchange byte in BL with byte in CH
8
STACK RELATED INSTRUCTIONS
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
18
• OUT Port, Accumulator
• The OUT instruction copies a byte from AL or
a word from AX to the specified port.
• Operation:
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.
• 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
28
• Example
• LDS BX, [4326]
• Copy content of memory location
4326H to BL,content of 4327H to BH
29
30
• Example
• LES BX, [4326]
• Copy content of memory location
4326H to BL,content of 4327H to BH
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
32
ARITHMETIC INSTRUCTIONS
33
ARITHMETIC INSTRUCTIONS
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.
38
• Operation
• a)If destination > source then
• CF=0, ZF=0, SF=0
39
• DAA (Decimal Adjust Accumulator)
• (DECIMAL ADJUST AFTER BCD ADDITION)
40
• Operation
• a)If lower nibble of AL>9 or AF=1
• then AL=AL+06
41
• Examples:
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
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
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.
• 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
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
JC disp8 Jump if CF = 1
JP disp8 Jump if PF = 1
JO disp8 Jump if OF = 1
JS disp8 Jump if SF = 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:
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.
96
97