The document describes various arithmetic instructions in the Intel 8086 microprocessor, including ADD, SUB, MUL, DIV, INC, DEC, CMP, NEG, CBW, CWD, AAA, and DAA. It provides details on the syntax, operation, examples and effects on flags for each instruction. A total of 20 arithmetic instructions are discussed that perform operations like addition, subtraction, multiplication, division, incrementing, decrementing and adjusting results.
1. Performs operations like add, sub, mul, div along
with respective ASCII and decimal adjust.
Also INC and DEC
These affect all the condition code flags
( O, A, P, S, Z, C )
20 instructions
Arithmetic Instructions
2. • ADD destination, source OR ADD source (destination is AX)
destination = destination + source
destination: register/ memory location
source: immediate data/ register/ memory location
source & destination both can not be memory locations
immediate data can not be the destination
Examples:
ADD AX, 0100H
ADDAX,BX
ADD AX, [5000H]
ADD [5000H], 0100H
ADD 0100H
Arithmetic Instructions
3. • ADC destination, source OR ADC source (destination is AX)
destination = destination + source + Carry flag
destination: register/ memory location
source: immediate data/ register/ memory location
source & destination both can not be memory locations
immediate data can not be the destination
Examples:
ADC AX, 0100H
ADCAX,BX
ADC AX, [5000H]
ADC [5000H], 0100H
ADC 0100H
Arithmetic Instructions
4. • SUB destination, source
Destination = destination – source
Destination: register/ memory location
Source: immediate data/ register/ memory location
source & destination both can not be memory locations
immediate data can not be the destination
Examples:
SUB AX, 0100H
SUB AX, BX
SUB AX, [5000H]
SUB [5000H], 0100H
Arithmetic Instructions
5. • SBB destination, source
Destination = destination – source – Carry flag
Destination: register/ memory location
Source: immediate data/ register/ memory location
source & destination both can not be memory locations
immediate data can not be the destination
Examples:
SBB AX, 0100H
SBB AX, BX
SBB AX, [5000H]
SBB [5000H], 0100H
Arithmetic Instructions
6. MUL (Unsigned multiplication)
Syntax :-- MUL source
• This instruction multiplies an unsigned byte
from source with an unsigned byte in AL
register
or
unsigned word from source with an unsigned
word in AX register.
• The source can be a register or memory
location but cannot be an immediate data.
7. MUL (Unsigned multiplication) Contd..
•When a byte is multiplied with a byte in AL, the
result is stored in AX.
• When a word is multiplied with a word in AX, the
MSW (Most Significant Word ) of the result is stored
in DX and the LSW (Least Significant Word ) of the
result is stored in AX.
• If MS Byte or Word of the result is zero, CF and OF
both will be set.
•All other flags are modified depending upon the
result
8. • Operation Performed :--
– If source is byte then AX AL * unsigned 8 bit
source
– If source is word then DX, AX AX * unsigned 16
bit source
Examples :--
1. MUL BL ; Multiply AL by BL & the result in AX
2. MUL CX ; Multiply AX by CX & the result in DX,AX
3. MUL Byte PTR [SI] ; AX AL * [SI]
MUL (Unsigned multiplication) Contd..
9. IMUL (Signed multiplication)
Syntax :-- IMUL source
• This instruction multiplies a signed byte from
source with a signed byte in AL register
or
signed word from source with an signed word
in AX register.
• The source can be a register, general purpose,
base or index, or memory location, but cannot
be an immediate data.
10. IMUL (Signed multiplication) Contd..
•When a byte is multiplied with a byte in
AL, the result is stored in AX.
• When a word is multiplied with a word
in AX, the MSW (Most Significant Word )
of the result is stored in DX and the LSW
(Least Significant Word ) of the result is
stored in AX.
11. IMUL (Signed multiplication) Contd..
•If the magnitude of the product does not
require all the bits of the destination, the
unused bits are filled with copies of the sign
bit.
•If AH and DX contain parts of the 16 & 32 bit
results, CF and OF are set, If the unused bits
are filled by the sign bit, OF and CF are
cleared.
12. • Operation Performed :--
– If source is byte then AX AL * signed 8 bit
source
– If source is word then DX, AX AX * signed 16 bit
source
Examples :--
1. IMUL BL ; Multiply AL by BL & the result in AX
2. IMUL CX ; Multiply AX by CX & the result in DX,AX
3. IMUL Byte PTR [SI] ; AX AL * [SI]
IMUL (Signed multiplication) Contd..
13. DIV (Unsigned Division)
Syntax :-- DIV source
• This instruction divides an unsigned word (16Bits)
in AX register by an unsigned byte (8Bits) from
source
or
an unsigned double word (32 bits) in DX & AX
register by an unsigned word (16bits) from source
• The source can be a register or memory location
but cannot be an immediate data.
14. DIV (Unsigned Division)Contd..
•When a word in AX is divided by a byte,
AL will contain the 8 bit quotient and AH
will contain an 8 bit remainder.
• When a double word in DX (MSW) &
AX (LSW) is divided by a word, AX will
contain the 16 bit quotient and DX will
contain an 16 bit remainder.
15. DIV (Unsigned Division)Contd..
•If a byte is to be divided by a byte, AL is
loaded with dividend and AH is filled with all
0’s.
•If a word is to be divided by a word, Ax is
loaded with dividend and DX is filled with all
0’s.
•If an attempt is made to divide by 0, or the
quotient is too large (FF or FFFF), type 0
interrupt is generated.
•No flags are affected.
16. • Operation Performed :--
–If source is byte then
• AL AX / unsigned 8 bit source ; (quotient)
• AH AX MOD unsigned 8 bit source ;
(remainder)
–If source is word then
• AX DX:AX / unsigned 16 bit source ;
(quotient)
• DX DX:AX MOD unsigned 16 bit source ;
(remainder)
DIV (Unsigned Division)Contd..
17. Examples :--
1. DIV BL ; Divide word in AX by byte in
BL, Quotient in AL, remainder
in AH.
2. DIV CX ; Divide double word in DX:AX
by word in CX, Quotient in AX,
Remainder in DX.
3. DIV [BX] ; Divide word in AX by byte in
memory location pointer by
BX.
DIV (Unsigned Division)Contd..
18. IDIV (Signed Division)
Syntax :-- IDIV source
• This instruction divides an signed word
(16Bits) in AX register by an signed byte (8Bits)
from source
or
An signed double word (32 bits) in DX & AX
register by an signed word (16bits) from
source
• The source can be a register or memory
location but cannot be an immediate data.
19. IDIV (Signed Division)Contd..
•When a word in AX is divided by a byte,
AL will contain the 8 bit quotient and AH
will contain an 8 bit remainder.
• When a double word in DX (MSW) &
AX (LSW) is divided by a word, AX will
contain the 16 bit quotient and DX will
contain an 16 bit remainder.
20. IDIV (Signed Division)Contd..
•If a byte is to be divided by a byte, AL is
loaded with dividend and AH is filled with all
0’s.
•If a word is to be divided by a word, Ax is
loaded with dividend and DX is filled with all
0’s.
•If an attempt is made to divide by 0, or the
quotient is too large (FF or FFFF), type 0
interrupt is generated.
•No flags are affected.
21. • Operation Performed :--
–If source is byte then
• AL AX / signed 8 bit source ; (quotient)
• AH AX MOD signed 8 bit source ;
(remainder)
–If source is word then
• AX DX:AX / signed 16 bit source ; (quotient)
• DX DX:AX MOD signed 16 bit source ;
(remainder)
IDIV (Signed Division)Contd..
22. Examples :--
1. IDIV BL ; Divide signed word in AX by
signed byte in BL, Quotient in
AL, remainder in AH.
2. IDIV CX ; Divide signed double word in
DX:AX by signed word in CX,
Quotient in AX, Remainder in
DX.
3. IDIV [BX] ; Divide signed word in AX by
signed byte in memory
location pointer by BX.
IDIV (Signed Division)Contd..
23. Example of division of a signed byte by
signed byte :--
MOV BL,divisor ; Load signed byte divisor in BL
MOV AL,dividend ; Load signed byte dividend in AL
CBW ;Extend sign of AL into AH
IDIV BL ; Byte division, Remainder in AH
and quotient in AL
24. DAA (Decimal Adjust Accumulator)
Syntax :-- DAA
• 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.
• After addition if the lower nibble is greater than 9 or
AF =1, it will add 06H to the lower nibble in AL.
• After this addition, if the upper nibble is greater than
9 or if CF = 1, DAA instruction adds 60H to AL.
• DAA instruction affects AF,CF,PF and ZF. OF is
undefined.
25. DAA Instruction contd..
• Operation Performed :--
– If lower nibble of AL > 9 or AF =1 then AL = AL +06
– If higher nibble of AL > 9 or CF =1 then AL = AL +60
27. Numeric Examples
AL = 73H, CL = 29H
ADD AL,CL ; AL AL + CL
;AL 73 + 29
;AL 9CH
DAA ; AL 02 and CF = 1 (as C>9)
28. DAS (Decimal Adjust After Subtraction)
Syntax :-- DAS
• This instruction is used to convert the result of the
subtraction of two packed BCD numbers to a valid BCD
number.
• The subtraction has to be only in AL.
• After subtraction if the lower nibble is greater than 9
or AF =1, it will subtract 06H from the lower nibble in
AL.
• If the result of the subtraction sets the carry flag or if
the upper nibble is greater than 9, DAS instruction
subtracts 60H from AL.
• DAS instruction affects AF,CF,PF and ZF. OF is
undefined.
29. DAS Instruction contd..
• Operation Performed :--
– If lower nibble of AL > 9 or AF =1 then AL = AL -06
– If higher nibble of AL > 9 or CF =1 then AL = AL -60
30. Numeric Examples
AL = 75, BH = 46
SUB AL,BH ; AL (AL) - (BH)
;AL 75 - 46
;AL 2FH
; AF = 1
DAS ; AL 2F - 06 (as F>9)
;AL 29
31. • INC operand
– Operand: register/ memory location
– Operand = operand +1
– Immediate data can not be the operand
INC AX is equivalent to ADD AX,01H
AX AX +1
Arithmetic Instructions
BX= 2500H,
[2500H]=36H
INC [BX]
BX=2500H,
[2500H]=37H
[5000H] = 39H
INC [5000H]
[5000H] = ??
32. • DEC operand
– Operand: register/ memory location
– Operand = operand -1
– Immediate data can not be the operand
DEC AX = SUB AX,01H
AX AX +1
Arithmetic Instructions
BX= 2500H,
[2500H]=36H
DEC [BX]
BX=2500H,
[2500H]=35H
[5000H] = 39H
DEC [5000H]
[5000H] = ??
33. Arithmetic Instructions
• CMP (Compare)
• Syntax :-- CMP destination, source
– This instruction compares the source operand, which may
be a register , immediate data or memory location with a
destination operand which may be a register or memory
location.
– It subtracts the source operand from the destination but
does not store the result anywhere.
– The flags (OF, CF, PF, AF, SF, ZF)are affected depending on
the result of subtraction.
– Source and destination both cannot be memory locations.
34. CMP Instruction contd..
• Operation Performed :--
– If destination > source then CF = 0, ZF = 0, SF = 0
– If destination < source then CF = 1, ZF = 0, SF = 1
– If destination = source then CF = 0, ZF = 1, SF = 0
Examples :--
1. CMP AL,0FFH ; Compares AL with FFH
2. CMP AX,BX ; Compares AX with BX
3. CMP CX, COUNT ; Compares CX with memory variable COUNT
35. CMP Instruction contd..
• Numeric Examples
• 1) If AL = 34,
After instruction , CMP AL,0FFH
what are the contents of CF , ZF & SF ?
• 2) If CX = 06H, COUNT = 06
After CMP CX, COUNT
CF = ?, ZF = ?, SF = ?
37. NEG ( Negate )
Syntax :-- NEG destination
• This instruction replaces the number in the
destination with the 2’s complement of that number.
• For obtaining the 2’s complement, it subtracts the
contents of destination from zero.
•The result is stored back in the destination which may
be a register or a memory location
38. CBW (Convert Signed Byte to Word)
Syntax :-- CBW
• This instruction converts a signed byte in
AL to a signed word and stores the result in
register AX.
•This instruction copies the sign of a byte in
AL to all the bits in AH.
• AH is then said to be the sign extension of
AL.
•CBW operation is done before performing
division of a signed byte in the AL by
another signed byte with IDIV instruction.
39. CBW (Convert Signed Byte to Word) contd..
Example :--
Suppose the contents of AL = 94H,
After CBW the result in AX is,
AL
AH AL
S D6 D5 D4 D3 D2 D1 D0
S S S S S S S S S D6 D5 D4 D3 D2 D1 D0
40. CWD (Convert Signed Word to Double Word)
Syntax :-- CWD
• This instruction copies the sign bit of a
word in AX to all the bits in DX.
• Thus the sign of AX is said to be
extended to DX.
•CWD operation is done before
performing division of a signed word in
the AX by another signed word with IDIV
instruction.
41. AAA (ASCII Adjust After Addition)
Syntax :-- AAA
• This instruction is used to convert the result in AL
after the addition of ASCII operands to decimal.
To perform the addition of two decimal numbers
using ASCII code, the following procedure is used:
•Transfer the ASCII code of 1st decimal digit into
register AL.
•Add AL with the ASCII code of 2nd decimal digit,
but the result obtained in AL will be invalid ASCII
code.
• Transfer 00H into AH.
•Convert invalid result of register AL into valid
unpacked BCD number, give AAA instruction.
42. • Logic Use for AAA:
i. If four LSBs of register AL are greater than
9 (1001) or AF = 1, then 6 is added
ii. Four MSBs of register AL are made 0000.
iii. The AF flag bit is copied into carry flag bit
and if AF = CF = 1, then the number in
register AH is increased by 1.
Note: Only 8 bit BCD number can be added at a
time and the first number should be present
in the register AL.
AAA (ASCII Adjust After Addition) contd..
43. • Note :--
–The instruction does not give exact ASCII
codes of the sum, but then can be obtained
by adding 3030 to AX.
• Example :--
MOV AH,00H
MOV AL,’5’ ; AL 35
ADD AL,’7’ ; AL 6Ch 35+37
AAA ;AX 0102H
ADD AX,3030H ; AX 3132H
AAA (ASCII Adjust After Addition) contd..
44. AAS (ASCII Adjust After Subtraction )
Syntax :-- AAS
• This instruction is used to convert the result in AL
after the subtraction of ASCII operands to decimal.
To perform the subtraction of two decimal numbers
using ASCII code, the following procedure is used:
•Transfer the ASCII code of 1st decimal digit into
register AL and Transfer 00H into AH.
•Subtract the ASCII code of 2nd decimal digit from
register AL, but the result obtained in AL will be
invalid ASCII code.
•Convert invalid result of register AL into valid
unpacked BCD number, give AAS instruction.
45. • Logic Use for AAA:
i. If four LSBs of register AL are greater than 9 (1001) or
AF = 1, then 6 is subtracted.
ii. Four MSBs of register AL are made 0000.
iii. The AF flag bit is copied into carry flag bit and if AF =
CF = 1, then the number in register AH is decreased by
1.
Note: Only 8 bit BCD number can be subtracted at a time and the
first number should be present in the register AL.
If after AAS instruction, the number in the register AH is 00, the
result is positive and ASCII code of the result is present in AL.
If after AAS instruction the number in register AH is FFH, then it
indicates the result is negative in 10s complement form.
AAS (ASCII Adjust After Subtraction) contd..
46. • Note :--
–The instruction does not give exact ASCII
codes of the difference, but then can be
obtained by adding 3030 to AX.
• Example :--
MOV AH,00H
MOV AL,’8’ ; AL 38
SUB AL,’2’ ; AL 06h 38-32
AAS ;AL 06H
ADD AL,30H ; AL 36H
AAA (ASCII Adjust After subtraction) contd..
47. AAM (ASCII Adjust After Multiplication)
Syntax :-- AAM
• This instruction is used to convert the product
in AL after the multiplication into unpacked
BCD format.
• The higher nibble of multiplication operands
is filled with zeros.
• The instruction should be used after MUL and
result is placed in the AX register.
•The binary number in AL register is divided by
10 and quotient is stored in the register AH,
Remainder in AL.
48. • Operation Performed :--
• AL = AL MOD 10
• AH = AL / 10
• Example :--
1. If AH = 0, AL = 06h , BL = 08h
• After MUL BL ; AL 30H
AAM ; AL 30H MOD 10 (48/10)
; AL 08
; AH AL / 10 (48 /10)
; AH 04
AH = 04h AL = 08h
AAM (ASCII Adjust After Multiplication) contd..
49. Program for the multiplication of two BCD numbers
DATA SEGMENT
A DB 7
B DB 4
R DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START: MOV AX,DATA
MOV DS,AX
MOV AL,A
MUL B
AAM
MOV CL,04
ROR AH,CL
ADD AL,AH
MOV R,AL
INT 3
CODE ENDS
END START
50. AAD (ASCII Adjust Before Division)
Syntax :-- AAD
• This instruction is used to convert the
unpacked BCD digits in AH and AL to the
equivalent binary number in the AL register.
• The higher nibble of AH and AL are filled with
zeros.
• The instruction should be used before
division instruction.
•The instruction will place the quotient in AL
register and Remainder in AH.
51. • Operation Performed :--
• AL = AH * 10 + AL
• AH = 00
• Example:--
1. If AH = 05, AL = 08 , BL = 07H
• After AAD ; AL 05 * 10 + 08
; AL 3AH
; AH 00H
DIV BL ; Quo 08H , Rem 02H
AH = 02h
AL = 08h
AAD (ASCII Adjust before Division) contd..
52. Program for the division of two BCD numbers
represented in ASCIIDATA SEGMENT
A DB ’57’
B DB ‘8’
Q DB ?
R DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START: MOV AX,DATA
MOV DS,AX
MOV AX,A
SUB AX,3030H
MOV BL,B
SUB BL,30H
AAD
DIV BL
MOV Q,AH
MOV R,AL
INT 3
CODE ENDS
END STASRT