#8086 Inst-Set Notes p-10-20
#8086 Inst-Set Notes p-10-20
This instruction copies a word or a byte of data from some source to a destination.
The destination can be a register or a memory location. The source can be a register, a
memory location, or an immediate number.
MOV AX, BX
MOV AX, 5000H
MOV AX, [SI]
MOV AX, [2000H]
MOV AX, [BX]
MOV [734AH], BX
MOV DS, CX
MOV CL, [357AH]
Direct loading of the segment registers with immediate data is not permitted.
PUSH: Push to Stack
This instruction pushes the contents of the specified register/memory location on to the
stack. The stack pointer is decremented by 2, after each execution of the instruction.
E.g. PUSH AX
• PUSH DS
• PUSH [5000H]
This instruction when executed, loads the specified register/memory location with
the contents of the memory location of which the address is formed using the
current stack segment and stack pointer.
Fig 1.8 Push into and Popping Register Content from Stack Memory
XCHG BX, AX
XLAT:
Translate byte using look-up table
Eg. LEA BX, TABLE1
MOV AL, 04H
XLAT
Input and output port transfer instructions:
IN:
Copy a byte or word from specified port to accumulator.
Eg. IN AL,03H
IN AX,DX
OUT:
Copy a byte or word from accumulator specified port.
Eg. OUT 03H, AL
OUT DX, AX
LEA:
Load effective address of operand in specified register.
[reg] offset portion of address in DS
Eg. LEA reg, offset
LDS:
Load DS register and other specified register from memory.
[reg] [mem]
[DS] [mem + 2]
Eg. LDS reg, mem
LES:
Load ES register and other specified register from memory.
[reg] [mem]
[ES] [mem + 2]
Eg. LES reg, mem
Flag transfer instructions:
LAHF:
Load (copy to) AH with the low byte the flag register.
[AH] [ Flags low byte]
Eg. LAHF
SAHF:
Store (copy) AH register to low byte of flag register.
[Flags low byte] [AH]
Eg. SAHF
PUSHF:
Copy flag register to top of stack.
[SP] [SP] – 2
[[SP]] [Flags]
Eg. PUSHF
POPF:
Copy word at top of stack to flag register.
[Flags] [[SP]]
[SP] [SP] + 2
1.4.2 Arithmetic Instructions:
12
MICROPROCESSOR & MICROCONTROLLER
INC: Increment
This instruction increases the contents of the specified Register or memory location by
1. Immediate data cannot be operand of this instruction.
Eg. INC AX
INC [BX]
INC [5000H]
DEC: Decrement
The decrement instruction subtracts 1 from the contents of the specified register or
memory location.
Eg. DEC AX
DEC [5000H]
NEG: Negate
The negate instruction forms 2’s complement of the specified destination in the
instruction. The destination can be a register or a memory location. This instruction can
be implemented by inverting each bit and adding 1 to it.
Eg. NEG AL
AL = 0011 0101 35H Replace number in AL with its 2’s complement
AL = 1100 1011 = CBH
13
MICROPROCESSOR & MICROCONTROLLER
CMP: Compare
This instruction compares the source operand, which may be a register or an immediate
data or a memory location, with a destination operand that may be a register or a
memory location
Eg. CMP BX, 0100H
CMP AX, 0100H
CMP [5000H], 0100H
CMP BX, [SI]
CMP BX, CX
MUL:Unsigned Multiplication Byte or Word
This instruction multiplies an unsigned byte or word by the contents of AL.
Eg. MUL BH; (AX) (AL) x (BH)
MUL CX; (DX)(AX) (AX) x (CX)
MUL WORD PTR [SI]; (DX)(AX) (AX) x ([SI])
IMUL:Signed Multiplication
This instruction multiplies a signed byte in source operand by a signed byte in AL or a
signed word in source operand by a signed word in AX.
Eg. IMUL BH
IMUL CX
IMUL [SI]
CBW: Convert Signed Byte to Word
This instruction copies the sign of a byte in AL to all the bits in AH. AH is then said to
be sign extension of AL.
Eg. CBW
AX= 0000 0000 1001 1000 Convert signed byte in AL signed word in AX. Result in
AX = 1111 1111 1001 1000
CWD: Convert Signed Word to Double Word
This instruction copies the sign of a byte in AL to all the bits in AH. AH is then said to
be sign extension of AL.
Eg. CWD
Convert signed word in AX to signed double word in DX: AX
DX= 1111 1111 1111 1111
Result in AX = 1111 0000 1100 0001
DIV: Unsigned division
This instruction is used to divide an unsigned word by a byte or to divide an unsigned
double word by a word.
Eg. DIV CL; Word in AX / byte in CL; Quotient in AL, remainder in AH
DIV CX; Double word in DX and AX / word; in CX, and Quotient in AX; remainder in
DX
AAA: ASCII Adjust After Addition
The AAA instruction is executed after an ADD instruction that adds two ASCII coded
operand to give a byte of result in AL. The AAA instruction converts the resulting
contents of Al to a unpacked decimal digits.
Eg. ADD CL, DL; [CL] = 32H = ASCII for 2; [DL] = 35H = ASCII for 5; Result [CL]
= 67H
MOV AL, CL; Move ASCII result into AL since; AAA adjust only [AL]
AAA; [AL]=07, unpacked BCD for 7
AAS: ASCII Adjust AL after Subtraction
This instruction corrects the result in AL register after subtracting two unpacked ASCII
operands. The result is in unpacked decimal format. The procedure is similar to AAA
instruction except for the subtraction of 06 from AL.
AAM: ASCII Adjust after Multiplication
14
MICROPROCESSOR & MICROCONTROLLER
This instruction, after execution, converts the product available In AL into unpacked
BCD format.
Eg. MOV AL, 04; AL = 04
MOV BL ,09; BL = 09
MUL BL; AX = AL*BL; AX=24H
AAM; AH = 03, AL=06
AAD: ASCII Adjust before Division
This instruction converts two unpacked BCD digits in AH and AL to the equivalent
binary number in AL. This adjustment must be made before dividing the two unpacked
BCD digits in AX by an unpacked BCD byte. In the instruction sequence, this
instruction appears Before DIV instruction.
Eg. AX 05 08
AAD result in AL 00 3A 58D = 3A H in AL
The result of AAD execution will give the hexadecimal number 3A in AL and 00 in
AH where 3A is the hexadecimal Equivalent of 58 (decimal).
DAA: Decimal Adjust Accumulator
This instruction is used to convert the result of the addition of two packed BCD
numbers to a valid BCD number. The result has to be only in AL.
Eg. AL = 53 CL = 29
ADD AL, CL; AL (AL) + (CL); AL 53 + 29;
AL 7C
DAA; AL 7C + 06 (as C>9); AL 82
Logical instructions
AND: Logical AND
This instruction bit by bit ANDs the source operand that may be an immediate register
or a memory location to the destination operand that may a register or a memory
location. The result is stored in the destination operand.
Eg. AND AX, 0008H
AND AX, BX
OR: Logical OR
This instruction bit by bit ORs the source operand that may be an immediate, register or
a memory location to the destination operand that may a register or a memory location.
The result is stored in the destination operand.
Eg. OR AX, 0008H
OR AX, BX
NOT: Logical Invert
This instruction complements the contents of an operand register or a memory location,
bit by bit.
Eg. NOT AX
NOT [5000H]
OR: Logical Exclusive OR
15
MICROPROCESSOR & MICROCONTROLLER
This instruction bit by bit XORs the source operand that may be an immediate, register
or a memory location to the destination operand that may a register or a memory
location. The result is stored in the destination operand.
Eg. XOR AX, 0098H
XOR AX, BX
TEST: Logical Compare Instruction
The TEST instruction performs a bit by bit logical AND operation on the two operands.
The result of this ANDing operation is not available for further use, but flags are
affected.
Eg. TEST AX, BX
TEST [0500], 06H
1.4. 3 Shift and Rotate Instructions
SAL/SHL: SAL / SHL destination, count.
SAL and SHL are two mnemonics for the same instruction. This instruction shifts each
bit in the specified destination to the left and 0 is stored at LSB position. The MSB is
shifted into the carry flag. The destination can be a byte or a word. It can be in a
register or in a memory location. The number of shifts is indicated by count.
Eg. SAL CX, 1
SAL AX, CL
SHR: SHR destination, count
This instruction shifts each bit in the specified destination to the right and 0 is stored at
MSB position. The LSB is shifted into the carry flag. The destination can be a byte or a
word.
It can be a register or in a memory location. The number of shifts is indicated by count.
Eg. SHR CX, 1
MOV CL, 05H
SHR AX, CL
SAR: SAR destination, count
This instruction shifts each bit in the specified destination some number of bit positions
to the right. As a bit is shifted out of the MSB position, a copy of the old MSB is put in
the MSB position. The LSB will be shifted into CF.
Eg. SAR BL, 1
MOV CL, 04H
SAR DX, CL
ROL Instruction: ROL destination, count
This instruction rotates all bits in a specified byte or word to the left some number of bit
positions. MSB is placed as a new LSB and a new CF.
Eg. ROL CX, 1
MOV CL, 03H
ROL BL, CL
ROR Instruction: ROR destination, count
This instruction rotates all bits in a specified byte or word to the right some number of
bit positions. LSB is placed as a new MSB and a new CF.
Eg. ROR CX, 1
MOV CL, 03H
ROR BL, CL
RCL Instruction: RCL destination, count
This instruction rotates all bits in a specified byte or word some number of bit positions
to the left along with the carry flag. MSB is placed as a new carry and previous carry is
place as new LSB.
Eg. RCL CX, 1
MOV CL, 04H
16
MICROPROCESSOR & MICROCONTROLLER
RCL AL, CL
RCR Instruction: RCR destination, count
This instruction rotates all bits in a specified byte or word some number of bit positions
to the right along with the carry flag. LSB is placed as a new carry and previous carry
is place as new MSB.
Eg. RCR CX, 1
MOV CL, 04H
RCR AL, CL
ROR Instruction: ROR destination, count
This instruction rotates all bits in a specified byte or word to the right some number of
bit positions. LSB is placed as a new MSB and a new CF.
Eg. ROR CX, 1
MOV CL, 03H
ROR BL, CL
RCL Instruction: RCL destination, count
This instruction rotates all bits in a specified byte or word some number of bit positions
to the left along with the carry flag. MSB is placed as a new carry and previous carry is
place as new LSB.
Eg. RCL CX, 1
MOV CL, 04H
RCL AL, CL
17
MICROPROCESSOR & MICROCONTROLLER
19
MICROPROCESSOR & MICROCONTROLLER
byte transfer (LODSB), the SI is modified by one and if it is a word transfer (LODSW),
the SI is modified by two. No other Flags are affected by this instruction.
STOS: Store String Byte or String Word
The STOS instruction Stores the AL / AX register contents to a location in the string
pointer by ES: DI register pair. The DI is modified accordingly, No Flags are affected
by this instruction.
The direction Flag controls the String instruction execution, The source index SI and
Destination Index DI are modified after each iteration automatically. If DF=1, then the
execution follows auto decrement mode, SI and DI are decremented automatically after
each iteration. If DF=0, then the execution follows auto increment mode. In this mode,
SI and DI are incremented automatically after each iteration.
1.4.7 Flag Manipulation and a Processor Control Instructions
These instructions control the functioning of the available hardware inside the
processor chip. These instructions are categorized into two types:
1. Flag Manipulation instructions.
2. Machine Control instructions.
Flag Manipulation instructions
The Flag manipulation instructions directly modify some of the Flags of 8086.
i. CLC – Clear Carry Flag.
ii. CMC – Complement Carry Flag.
iii. STC – Set Carry Flag.
iv. CLD – Clear Direction Flag.
v. STD – Set Direction Flag.
vi. CLI – Clear Interrupt Flag.
vii. STI – Set Interrupt Flag.
1.4.8 Machine Control instructions
The Machine control instructions control the bus usage and execution
i. WAIT – Wait for Test input pin to go low.
ii. HLT – Halt the process.
iii. NOP – No operation.
iv. ESC – Escape to external device like NDP
v. LOCK – Bus lock instruction prefix.
20