8086 Instructions 1
8086 Instructions 1
(ENEX 201)
Sharad Kumar Ghimire
Department of Electronics and Computer Engineering
Pulchowk Campus
Institute of Engineering
Tribhuvan University
Nepal
Chapter 3
S. K. Ghimire
8086 Microprocessor Instruction Set
The 8086 microprocessor instructions
Data Transfer Instructions
Arithmetic Instructions
Logical Instructions
Interrupt Instructions
String Instructions
Contents
8086 Microprocessor Instructions:
Arithmetic: ADD, ADC, SUB, SBB, MUL, IMUL, DIV, IDIV, INC, DEC, DAA,
DAS, CBW, CWD
Rotate & Shift: RCL, RCR, ROL, ROR, SAL/SHL, SAR, SHR
- S. K. Ghimire
DATA TRANSFER INSTRUCTIONS
MOV – MOV Destination, Source
Copies a word or byte of data from a specified source to a specified destination
Source and destination must both be of the same type (bytes or words)
E.g.
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
The word from the first two memory locations is copied into the specified register,
and the word from the next two memory locations is copied into the ES register
ADC - also adds the status of the carry flag to the result
The source and the destination both cannot be memory locations at once
The source and the destination must be of the same type (bytes or words)
SBB instruction also subtracts the content of carry flag from the destination
The source and the destination both cannot be memory location at once
The source and the destination must both be of the same type (bytes or words)
When a byte is multiplied by the content of AL, the result (product) is put in AX
When a word is multiplied by the content of AX, the result is put in DX and AX
registers
CF & OF affected but AF, PF, SF and ZF are undefined after a MUL instruction
IMUL BH ;Multiply signed byte in AL with signed byte in BH; result in AX.
When a byte is used as divisor the content of AX register is divided and AL will
contain the 8-bit quotient, and AH will contain the 8-bit remainder
When a word is used as divisor the 32 bit contents of DX:AX is divided and AX will
contain the 16-bit quotient and DX will contain the 16-bit remainder
The flags AF, OF, PF, SF, and ZF are updated whereas CF remain unaffected
INC BYTE PTR [BX] ;Increment byte in data segment at offset contained in BX
INC WORD PTR [BX] ;Increment the word pointed by BX in the data segment
DEC – DEC Destination
Subtracts 1 from the destination word or byte
The flags AF, OF, SF, PF, and ZF are affected, whereas CF is unchanged
DX = 11111111 11111111
8086 allows to add the ASCII codes for two decimal digits without masking off the
“3” in the upper nibble of each. After the addition, the AAA instruction is used to
make sure the result is the correct unpacked BCD
AAA instruction updates AF and CF; but OF, PF, SF and ZF are left undefined
AAS (ASCII ADJUST FOR SUBTRACTION)
Numerical data coming into a computer from a terminal is usually in ASCII code
In this code the numbers 0 to 9 are represented by the ASCII codes 30H to 39H
8086 allows to subtract the ASCII codes for two decimal digits without masking the
“3” in the upper nibble of each
AAS instruction is then used to make sure the result is the correct unpacked BCD
Updates ZF and CF; but OF, PF, SF, AF are left undefined
AAM (BCD ADJUST AFTER MULTIPLY)
Before multiplying two ASCII digits, we have to mask the upper 4 bit of each - this
leaves unpacked BCD (one BCD digit per byte) in each byte
After the two unpacked BCD digits are multiplied, the AAM instruction is used to
adjust the product to two unpacked BCD digits in AX
AAM works only after the multiplication of two unpacked BCD bytes, and it works
only the operand in AL
AAM updates PF, SF and ZF but AF; CF and OF are left undefined
AAD (BCD-TO-BINARY CONVERT BEFORE
DIVISION)
AAD 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
After the BCD division, AL will contain the unpacked BCD quotient and AH will
contain the unpacked BCD remainder
LOGICAL INSTRUCTIONS
AND – AND Destination, Source
Performs bitwise AND operation source byte or word with the same numbered bit
in a destination byte or word, and 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, but the destination can be a register or a memory location
CF and OF are both 0 and PF, SF, and ZF are updated by the AND instruction. AF
is undefined. PF has meaning only for an 8-bit operand
OR – OR Destination, Source
Performs OR operation each bit in a source byte or word with the same numbered
bit in a destination byte or word and 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, whereas the destination can be a register or a memory
CF, OF are both 0, and PF, SF, and ZF are updated by the OR instruction. AF is
undefined. PF has meaning only for an 8-bit operand
XOR – XOR Destination, Source
Exclusive-OR operation of each bit in a source byte or word with the same
numbered bit in a destination byte or word and 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 whereas the destination can be a register or a memory
CF, OF are both 0 and PF, SF, and ZF are updated. PF has meaning only for an
8-bit operand. AF is undefined
NOT – NOT Destination
Inverts each bit (forms the 1’s complement) of a byte or word in the specified
destination
NOT BX
It gives the same result as the invert each bit and add one algorithm
NEG AL
NEG BX
The comparison is actually done by subtracting the source byte or word from the
destination byte or word, without changing the source and the destination, but the
flags are set to indicate the results of the comparison
The test instruction is often used to set flags before a Conditional jump instruction
CF and OF are both 0’s after TEST. PF, SF and ZF will be updated to show the
results of the destination. AF is be undefined