SlideShare a Scribd company logo
1 of 52
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
• 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
• 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
• 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
• 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
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.
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
• 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..
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.
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.
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.
• 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..
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.
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.
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.
• 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..
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..
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.
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.
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.
• 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..
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..
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
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.
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
Numeric Examples
AL = 53H, CL = 29H
ADD AL,CL ; AL  AL + CL
;AL  53 + 29
;AL  7CH
DAA ; AL 7C +06 (as C>9)
;AL 82
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)
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.
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
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
• 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] = ??
• 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] = ??
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.
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
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 = ?
Answers :--
1.
• CF = 1
• ZF = 0
• SF = 1
2.
• CF = 0
• ZF = 1
• SF = 0
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
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.
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
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.
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.
• 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..
• 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..
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.
• 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..
• 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..
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.
• 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..
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
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.
• 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..
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

More Related Content

What's hot

Arithmetic and logical instructions set
Arithmetic and logical instructions setArithmetic and logical instructions set
Arithmetic and logical instructions setRobert Almazan
 
Ascii adjust & decimal adjust
Ascii adjust & decimal adjustAscii adjust & decimal adjust
Ascii adjust & decimal adjustTech_MX
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructionsRobert Almazan
 
Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Srimatre K
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instructionkashif Shafqat
 
8086 Microprocessor Instruction set
8086 Microprocessor Instruction set8086 Microprocessor Instruction set
8086 Microprocessor Instruction setVijay Kumar
 
Instructionset8085
Instructionset8085Instructionset8085
Instructionset8085Fawad Pathan
 
MICROPROCESSOR INSTRUCTION SET OF 8085
MICROPROCESSOR INSTRUCTION SET OF 8085MICROPROCESSOR INSTRUCTION SET OF 8085
MICROPROCESSOR INSTRUCTION SET OF 8085Sumadeep Juvvalapalem
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Bilal Amjad
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086Mahalakshmiv11
 
itft-Instruction set-of-8085
itft-Instruction set-of-8085itft-Instruction set-of-8085
itft-Instruction set-of-8085Shifali Sharma
 
Push down automata
Push down automataPush down automata
Push down automataSomya Bagai
 
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086COMSATS Abbottabad
 

What's hot (19)

8086 Instruction set
8086 Instruction set8086 Instruction set
8086 Instruction set
 
Arithmetic and logical instructions set
Arithmetic and logical instructions setArithmetic and logical instructions set
Arithmetic and logical instructions set
 
Ascii adjust & decimal adjust
Ascii adjust & decimal adjustAscii adjust & decimal adjust
Ascii adjust & decimal adjust
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructions
 
Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instruction
 
8086 Microprocessor Instruction set
8086 Microprocessor Instruction set8086 Microprocessor Instruction set
8086 Microprocessor Instruction set
 
Instructionset8085
Instructionset8085Instructionset8085
Instructionset8085
 
Pda
PdaPda
Pda
 
MICROPROCESSOR INSTRUCTION SET OF 8085
MICROPROCESSOR INSTRUCTION SET OF 8085MICROPROCESSOR INSTRUCTION SET OF 8085
MICROPROCESSOR INSTRUCTION SET OF 8085
 
Introduction to 8085 by adi ppt
Introduction to 8085 by adi pptIntroduction to 8085 by adi ppt
Introduction to 8085 by adi ppt
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
 
Push down automata
Push down automataPush down automata
Push down automata
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086
 
arithmetic ins in 8051
arithmetic ins in 8051arithmetic ins in 8051
arithmetic ins in 8051
 
itft-Instruction set-of-8085
itft-Instruction set-of-8085itft-Instruction set-of-8085
itft-Instruction set-of-8085
 
Push down automata
Push down automataPush down automata
Push down automata
 
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086
 

Similar to Chapter 3 8086 ins2 math

8086 instructions
8086 instructions8086 instructions
8086 instructionsRavi Anand
 
Topic 6 - Programming in Assembly Language_230517_115118.pdf
Topic 6 - Programming in Assembly Language_230517_115118.pdfTopic 6 - Programming in Assembly Language_230517_115118.pdf
Topic 6 - Programming in Assembly Language_230517_115118.pdfezaldeen2013
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086Vijay Kumar
 
Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)AmitPaliwal20
 
8086 instruction set
8086 instruction set8086 instruction set
8086 instruction setmeenakshi_l
 
Mastering Assembly Language: Programming with 8086
Mastering Assembly Language: Programming with 8086Mastering Assembly Language: Programming with 8086
Mastering Assembly Language: Programming with 8086sravanithonta79
 
Bcd and ascii arithmetic instructions
Bcd and ascii arithmetic instructionsBcd and ascii arithmetic instructions
Bcd and ascii arithmetic instructionsDr. Girish GS
 
Ascii arithmetic instructions
Ascii arithmetic instructionsAscii arithmetic instructions
Ascii arithmetic instructionsDr. Girish GS
 
Bcd arithmetic instructions
Bcd arithmetic instructionsBcd arithmetic instructions
Bcd arithmetic instructionsDr. Girish GS
 
instruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptinstruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptssuser2b759d
 
Instruction 4.pptx
Instruction 4.pptxInstruction 4.pptx
Instruction 4.pptxHebaEng
 
Microprocessor 8086 instruction description
Microprocessor 8086 instruction descriptionMicroprocessor 8086 instruction description
Microprocessor 8086 instruction descriptionDheeraj Suri
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptxNishatNishu5
 

Similar to Chapter 3 8086 ins2 math (20)

8086 instructions
8086 instructions8086 instructions
8086 instructions
 
Topic 6 - Programming in Assembly Language_230517_115118.pdf
Topic 6 - Programming in Assembly Language_230517_115118.pdfTopic 6 - Programming in Assembly Language_230517_115118.pdf
Topic 6 - Programming in Assembly Language_230517_115118.pdf
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)
 
Notes all instructions
Notes all instructionsNotes all instructions
Notes all instructions
 
8086 instruction set
8086 instruction set8086 instruction set
8086 instruction set
 
8086 instruction set
8086 instruction set8086 instruction set
8086 instruction set
 
Mastering Assembly Language: Programming with 8086
Mastering Assembly Language: Programming with 8086Mastering Assembly Language: Programming with 8086
Mastering Assembly Language: Programming with 8086
 
Bcd and ascii arithmetic instructions
Bcd and ascii arithmetic instructionsBcd and ascii arithmetic instructions
Bcd and ascii arithmetic instructions
 
Ascii arithmetic instructions
Ascii arithmetic instructionsAscii arithmetic instructions
Ascii arithmetic instructions
 
Bcd arithmetic instructions
Bcd arithmetic instructionsBcd arithmetic instructions
Bcd arithmetic instructions
 
instruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptinstruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.ppt
 
Instruction 4.pptx
Instruction 4.pptxInstruction 4.pptx
Instruction 4.pptx
 
Instruction set
Instruction setInstruction set
Instruction set
 
Microprocessor 8086 instruction description
Microprocessor 8086 instruction descriptionMicroprocessor 8086 instruction description
Microprocessor 8086 instruction description
 
Mod-2.pptx
Mod-2.pptxMod-2.pptx
Mod-2.pptx
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptx
 
Module 2 (1).pptx
Module 2 (1).pptxModule 2 (1).pptx
Module 2 (1).pptx
 
Al2ed chapter11
Al2ed chapter11Al2ed chapter11
Al2ed chapter11
 
Notes aaa aa
Notes aaa aaNotes aaa aa
Notes aaa aa
 

More from HarshitParkar6677 (20)

Wi fi hacking
Wi fi hackingWi fi hacking
Wi fi hacking
 
D dos attack
D dos attackD dos attack
D dos attack
 
Notes chapter 6
Notes chapter  6Notes chapter  6
Notes chapter 6
 
Interface notes
Interface notesInterface notes
Interface notes
 
Chapter6 2
Chapter6 2Chapter6 2
Chapter6 2
 
Chapter6
Chapter6Chapter6
Chapter6
 
8086 cpu 1
8086 cpu 18086 cpu 1
8086 cpu 1
 
Chapter 6 notes
Chapter 6 notesChapter 6 notes
Chapter 6 notes
 
Chapter 5 notes
Chapter 5 notesChapter 5 notes
Chapter 5 notes
 
Chap6 procedures &amp; macros
Chap6 procedures &amp; macrosChap6 procedures &amp; macros
Chap6 procedures &amp; macros
 
Chapter 5 notes new
Chapter 5 notes newChapter 5 notes new
Chapter 5 notes new
 
Notes 8086 instruction format
Notes 8086 instruction formatNotes 8086 instruction format
Notes 8086 instruction format
 
Misc
MiscMisc
Misc
 
Copy of 8086inst logical
Copy of 8086inst logicalCopy of 8086inst logical
Copy of 8086inst logical
 
Copy of 8086inst logical
Copy of 8086inst logicalCopy of 8086inst logical
Copy of 8086inst logical
 
Chapter3 program flow control instructions
Chapter3 program flow control instructionsChapter3 program flow control instructions
Chapter3 program flow control instructions
 
Chapter3 8086inst stringsl
Chapter3 8086inst stringslChapter3 8086inst stringsl
Chapter3 8086inst stringsl
 
Chapter3 8086inst logical 2
Chapter3 8086inst logical 2Chapter3 8086inst logical 2
Chapter3 8086inst logical 2
 
Chap3 program flow control instructions
Chap3 program flow control instructionsChap3 program flow control instructions
Chap3 program flow control instructions
 
Chap3 8086 logical
Chap3 8086 logicalChap3 8086 logical
Chap3 8086 logical
 

Recently uploaded

COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086anil_gaur
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf203318pmpc
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 

Recently uploaded (20)

COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 

Chapter 3 8086 ins2 math

  • 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
  • 26. Numeric Examples AL = 53H, CL = 29H ADD AL,CL ; AL  AL + CL ;AL  53 + 29 ;AL  7CH DAA ; AL 7C +06 (as C>9) ;AL 82
  • 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 = ?
  • 36. Answers :-- 1. • CF = 1 • ZF = 0 • SF = 1 2. • CF = 0 • ZF = 1 • SF = 0
  • 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