SlideShare a Scribd company logo
1 of 51
TOPIC:
MULTIPLICATI
ON AND
DIVISION
Group member:
M Hamza Nasir
(12063122-067)
M Usaman Ali
(12063122-086)
Syed Farhan Abbas
(12063122-009)
M Faran Ali
(12063122-055)
Ateeb Saeed
(12063122-094)
University Of Gujrat
Multiplication
MUL(unsinged
)
IMUL(singed)
MUL INSTRUCTION
(UNSIGNED MULTIPLY)
Multiplies an 8-, 16-, or 32-bit operand by
either AL, AX
Syntax:MUL AL R/M8
Syntax: MUL AX R/M16
MUL INSTRUCTION
īƒ˜Note that the product is stored in a register (or
group of registers) twice the size of the
operands.
īƒ˜The operand can be a register or a memory
operand
MUL INSTRUCTION
MUL EXAMPLES
Mov al, 5h
Mov bl, 10h
Mul bl ; AX = 0050h, CF = 0
īƒ˜ No overflow - the Carry flag is 0 because the
upper half of AX is zero
IMUL INSTRUCTION
(SIGNED MULTIPLY)
īƒ˜same syntax
īƒ˜uses the same operands as the MUL
instruction
īƒ˜ preserves the sign of the product
īƒ˜Opcode=IMUL
IMUL INSTRUCTION
īƒ˜Suppose AX contains 1 and BX contains FFFFh
Mov AX, 1h
Mov BX, FFFFh
IMUL BX ;
Decimal product=-1,
Hex Product =FFFFFFFFh
DX = FFFFh, AX=FFFFh CF/OF=0
DX is a sign extension of AX for this CF/OF=0
IMUL INSTRUCTION
īƒ˜IMUL sets the Carry and Overflow flags if the
high-order product is not a sign extension of
the low-order product
Mov al, 48
Mov bl, 4
Imul bl ;AX = 00C0h, OF = 1
AH is not a sign extension of AL, so the
Overflow flag is set
IMUL INSTRUCTION
Suppose AX contains FFFFh and BX contains FFFFh
Mov AX, FFFFH
Mov BX, FFFFh
IMUL BX
Decimal product=1
Hex Product = 00000001 h
DX = 0000h, AX=0001h CF/OF=0
DX is a sign extension of AX for this CF/OF=0
IMUL INSTRUCTION
īƒ˜Suppose AX contains 0FFFh.and BX contains 0FFFh
Mov AX, 0FFFH
Mov BX, 0FFFh
IMUL BX
Decimal product=16769025
Hex Product = 00FFE001 h
DX = 00FFh, AX=E001h CF/OF=0
DX is a not sign extension of AX for this CF/OF=1
IMUL INSTRUCTION
īƒ˜Suppose AL contains 80h.and BL contains FFh
Mov AL, 80H
Mov BL, FFh
IMUL BL
Decimal product=128,
Hex Product = 0080 h
AH = 00h, AL=80h CF/OF=01
DX is a not sign extension of AX for this CF/OF=1
APPLICATION OF MUL AND IMUL
īƒ˜Translate the high level language assignment
statement
īƒ˜A=5×A-12×B
īƒ˜Let A and B be word variables, and suppose
there is no overflow.
īƒ˜Use IMUL for multiplication
SOLUTION:
īƒ˜Mov AX,5 ;AX=5
īƒ˜IMUL A ;AX=5*A
īƒ˜MOV A,AX ;A=5*A
īƒ˜MOV AX,12 ;AX=12
īƒ˜IMUL B ;AX=12*B
īƒ˜SUB A,AX ;5*A-12*B
DIVIDE
DIV(unsinged) IDIV(singed)
DIVIDE AND IDIVIDE
īƒ˜When division is performed we obtain two
results
īƒ˜The quotient and
īƒ˜The remainder.
īƒ˜Similarly like Multiplication there are separate
instructions for unsigned and signed division
CONT..
Syntax:
DIV divisor
IDIV divisor
Byte Form:
The divisor is eight bit register or memory byte
The 16 – bit dividend is assumed to be in AX. After
division 8-bit quotient is in AL and 8-bit remainder in
AH.
CONT..
Word Form:
The divisor is a 16-bit register or memory word
The 32-bit dividend is assumed to be in DX:AX
After division, the 16-bit quotient is in AX and 16-
bit remainder is in DX
Effect on flags:
All status flags are undefined
CONT..
Divide Overflow:
īƒ˜It is possible that the quotient s too big to fit
in the specified destination(AL or AX).
īƒ˜This Happens Because the divisor is much
smaller than the dividend.
īƒ˜When this Happens the program terminates
and system displays message “divide overflow”
CONT..
Examples:
EXAMPLE 9.8:
Suppose DX contains 0000h , AX contains 0005h, and BX
contains 0002h.
EXAMPLE 9.9:
Suppose DX contains 0000h , AX contains 0005h and BX
contains FFFEh.
EXAmple 9.10:
Suppose AX contains 00FBh and BL contains FFh.
DECIMAL INPUT AND
OUTPUT
īƒ˜Computer represent every thing in binary
īƒ˜But it is convenient for user to represent
input and output in decimal
īƒ˜If we input 21543 character string then it
must to converted internally
īƒ˜Conversely on output the binary contents of
R/M must be converted to decimal equivalent
before being printed
DECIMAL INPUT
īƒ˜Convert a string of ASCII digits to the binary
representation of decimal equivalent
īƒ˜For input we repeatedly multiply AX by 10
Algorithm (First version):
Total=0
Read an ASCII
REPEAT
convert character to number
Total=total*10+value
Read a character
Until character is carriage return
CONT..
Example: input of 123
Total =0
Read ‘1’
Convert ‘1’ to 1
Total=10*0 +1=1
Read ‘2’
Convert ‘2’ to 2
Total=10*1 +2=12
Read ‘3’
Convert ‘3’ to 3
Total=10*12 +3=123
CONT..
īƒ˜Range: -32768 to 32767
īƒ˜Optional sign followed by string of digits
& carriage return
īƒ˜Outside ‘0’ to ‘9’
īƒ˜jumps to new line and ask for input
again
CONT..
Algorithm(second version):
total=0
Negative=false
Read a character
Case character of
â€ĸ ‘-’: negative=true
read a character
â€ĸ ‘+’: read a character
End_case
Repeat
If character is not between ‘0’ to ‘9’
Then
Go to beginning
CONT..
Else
Convert character to binary value
Total=10*total+value
End_if
Read a character
Until character is carriage return
If negative =true
Then
total=-total
CONT..
Program(source code):
INDEC PROC
;READ NUMBER IN RANGE -32768 TO 32767
PUSH BX
PUSH CX
PUSH DX
@BEGIN:
;total =0
XOR BX,BX ;BX hold total
;negative =false
CONT..
XOR CX,CX ;CX hold sign
;read char
MOV AH,1
INT 21H
;case char of
CMP AL,'-' ;minus sign
JE @MINUS ;yes,set sign
CMP AL,'+' ;plus sign
JE @PLUS ;yes,get another char
CONT..
JMP @REPEAT2 ;start processing char
@MINUS: MOV CX,1
@PLUS: INT 21H
;end case
@REPEAT2:
;if char. is between '0' and '9'
CMP AL,'0' ;char >='0'?
JNGE @NOT_DIGIT ;illegal char.
CONT..
CMP AL,'9' ;char<='9' ?
JNLE @NOT_DIGIT
;then convert char to digit
AND AX,000FH
PUSH AX ;save number
;total =total *10 +digit
MOV AX,10
MUL BX
POP BX ;retrieve number
ADD BX,AX ;total =total *10
+digit
CONT..
;read char
MOV AH,1
INT 21H
CMP AL,0DH ;CR
JNE @REPEAT2 ;no keep going
;until CR
MOV AX,BX ;store number
in AX
;if negative
OR CX,CX ;negative
CONT..
Jz @EXIT ;no,exit
;then
NEG AX ;yes,negate
;end if
@EXIT: ;retrieve registers
POP DX
POP CX
POP BX
RET
CONT..
;here if illegal char entered
@NOT_DIGIT:
MOV AH,2
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H
JMP @BEGIN
INDEC ENDP
CONT..
Output:
INPUT OVERFLOW
īƒ˜AX:FFFFh
īƒ˜In decimal:65535
īƒ˜Range:-32768 to 32767
īƒ˜Anything out of range called input overflow
īƒ˜For example:
īƒ˜Input:32769
īƒ˜Total=327690
CONT..
Algorithm:
total=0
Negative=false
Read a character
Case character of
â€ĸ ‘-’: negative=true
read a character
â€ĸ ‘+’: read a character
CONT..
End_case
Repeat
If character is not between ‘0’ to ‘9’
Then
Go to beginning
Else
Convert character to binary value
Total=10*total
CONT..
If overflow
Then
go to beginning
Else
Total =total*10 +value
If overflow
Then
go to beginning
CONT..
End_if
End_if
End_if
Read a character
Until character is carriage return
If negative =true
Then
total=-total
CONT..
Code:
;total =total *10 +digit
MOV AX,10
MUL BX
CMP DX,0
JNE @NOT_DIGIT
POP BX
ADD BX,AX
JC @NOT_DIGIT
CONT..
Output:
Decimal Output
Algorithm for Decimal Output:
īƒ˜If AX < 0 /*AX holds output value */
īƒ˜THEN
īƒ˜Print a minus sign
īƒ˜Replace AX by its twos complement
īƒ˜End_IF
īƒ˜Get the digits in AX’s decimal representation
īƒ˜Convert these digits into characters and print
them
CONT..
To see what line 6 entitles, suppose the contents of
AX, expressed in decimal is 24168. To get the digits
in decimal representation , we can proceed as
follows,
īƒ˜Divide 24618 by 10, Quotient= 2461,
remainder=8
īƒ˜Divide 2461 by 10, Quotient= 246, remainder=1
īƒ˜Divide 246 by 10 , Quotient=24, remainder=6
īƒ˜Divide 24 by 10, Quotient=2, remainder=4
īƒ˜Divide 2 by 10, Quotient=0, remainder=2
CONT..
LINE 6:
Cout =0 /*will count decimal digit */
REPEAT
divide quotient by 10
Push remainder on the stack
Count= count +1
UNTILL
Quotient=0
CONT..
LINE 7:
FOR count times DO
Pop a digit from the stack
Convert it to a character
Output the character
END_FOR
CONT..
Program Listing PMG9_1.ASM
.MODEL SMALL
.STACK 100H
.CODE
OUTDEC PROC
;prints AX as a signed decimal integer
;input: AX
;output: none
PUSH AX ;save registers
PUSH BX
PUSH CX
PUSH DX
CONT..
;if AX < 0
OR AX,AX ;AX < 0?
JGE @END_IF1 ;NO >0
;then
PUSH AX ; save number
MOV DL,’-’ ;get ‘-’
MOV AH,2 ;print character function
INT 21H ;print ‘-’
POP AX ;get Ax back
NEG AX ;AX= -AX
@END_IF1:
CONT..
;get decimal digits
XOR CX,CX ;CX counts digits
MOV BX,10D ;BX has divisor
@REPEAT1:
XOR DX,DX ;prepare high word of dividend
DIV BX ;AX=quotient, DX=remainder
PUSH DX ;save remainder on stack
INC CX ;count = count +1
;until
OR AX,AX ;quotient = 0?
JNE @REPEAT ;no, keep going
CONT..
;convert digits to character and print
MOV AH,2 ;print character function
;for count time do
@PRINT_LOOP
POP DX ;digit in DL
OR DL,30H ;convert to character
INT 21H ;print digit
;end_for
POP DX ; restore registers
POP CX
POP BX
POP AX
OUTDEC ENDP
Multiplication & division instructions microprocessor 8086

More Related Content

What's hot

Interrupts of 8086
Interrupts of 8086Interrupts of 8086
Interrupts of 8086Albin Panakkal
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 
Chapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registersChapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registerswarda aziz
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorAshita Agrawal
 
Interrupts of microprocessor 8085
Interrupts of microprocessor  8085Interrupts of microprocessor  8085
Interrupts of microprocessor 8085mujeebkhanelectronic
 
System bus timing 8086
System bus timing 8086System bus timing 8086
System bus timing 8086mpsrekha83
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architectureprasadpawaskar
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instructionkashif Shafqat
 
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...Bilal Amjad
 
Microprogrammed Control Unit
Microprogrammed Control UnitMicroprogrammed Control Unit
Microprogrammed Control UnitPreethiSureshkumar1
 
chapter 7 Logic, shift and rotate instructions
chapter 7 Logic, shift and rotate instructionschapter 7 Logic, shift and rotate instructions
chapter 7 Logic, shift and rotate instructionswarda aziz
 
Clock-8086 bus cycle
Clock-8086 bus cycleClock-8086 bus cycle
Clock-8086 bus cycleRani Rahul
 
Logical and shift micro operations
Logical and shift micro operationsLogical and shift micro operations
Logical and shift micro operationsSanjeev Patel
 
Logical Instructions used in 8086 microprocessor
Logical Instructions used in 8086 microprocessorLogical Instructions used in 8086 microprocessor
Logical Instructions used in 8086 microprocessorRabin BK
 
8085 interfacing with memory chips
8085 interfacing with memory chips8085 interfacing with memory chips
8085 interfacing with memory chipsSrikrishna Thota
 
Addressing mode Computer Architecture
Addressing mode  Computer ArchitectureAddressing mode  Computer Architecture
Addressing mode Computer ArchitectureHaris456
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor Mustapha Fatty
 
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
 
Unit 4-booth algorithm
Unit 4-booth algorithmUnit 4-booth algorithm
Unit 4-booth algorithmvishal choudhary
 
8086 memory interface.pptx
8086 memory interface.pptx8086 memory interface.pptx
8086 memory interface.pptxHebaEng
 

What's hot (20)

Interrupts of 8086
Interrupts of 8086Interrupts of 8086
Interrupts of 8086
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
Chapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registersChapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registers
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 Microprocessor
 
Interrupts of microprocessor 8085
Interrupts of microprocessor  8085Interrupts of microprocessor  8085
Interrupts of microprocessor 8085
 
System bus timing 8086
System bus timing 8086System bus timing 8086
System bus timing 8086
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instruction
 
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
 
Microprogrammed Control Unit
Microprogrammed Control UnitMicroprogrammed Control Unit
Microprogrammed Control Unit
 
chapter 7 Logic, shift and rotate instructions
chapter 7 Logic, shift and rotate instructionschapter 7 Logic, shift and rotate instructions
chapter 7 Logic, shift and rotate instructions
 
Clock-8086 bus cycle
Clock-8086 bus cycleClock-8086 bus cycle
Clock-8086 bus cycle
 
Logical and shift micro operations
Logical and shift micro operationsLogical and shift micro operations
Logical and shift micro operations
 
Logical Instructions used in 8086 microprocessor
Logical Instructions used in 8086 microprocessorLogical Instructions used in 8086 microprocessor
Logical Instructions used in 8086 microprocessor
 
8085 interfacing with memory chips
8085 interfacing with memory chips8085 interfacing with memory chips
8085 interfacing with memory chips
 
Addressing mode Computer Architecture
Addressing mode  Computer ArchitectureAddressing mode  Computer Architecture
Addressing mode Computer Architecture
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor
 
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,...
 
Unit 4-booth algorithm
Unit 4-booth algorithmUnit 4-booth algorithm
Unit 4-booth algorithm
 
8086 memory interface.pptx
8086 memory interface.pptx8086 memory interface.pptx
8086 memory interface.pptx
 

Viewers also liked

8086 assembly language
8086 assembly language8086 assembly language
8086 assembly languageMir Majid
 
microprocessor 8086 lab manual !!
microprocessor 8086 lab manual !!microprocessor 8086 lab manual !!
microprocessor 8086 lab manual !!Sushil Mishra
 
Ascii adjust & decimal adjust
Ascii adjust & decimal adjustAscii adjust & decimal adjust
Ascii adjust & decimal adjustTech_MX
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5Motaz Saad
 
Flags registor of 8086 processor
Flags registor of 8086 processorFlags registor of 8086 processor
Flags registor of 8086 processorFazle Akash
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructionsRobert Almazan
 
Chapter 3
Chapter 3Chapter 3
Chapter 3ececourse
 
05 multiply divide
05 multiply divide05 multiply divide
05 multiply dividePiyush Rochwani
 
Introduction to 8085 Microprocessor
Introduction to 8085 MicroprocessorIntroduction to 8085 Microprocessor
Introduction to 8085 MicroprocessorRavi Anand
 
Wireless sensors network in Avionic control system
Wireless sensors network in Avionic control systemWireless sensors network in Avionic control system
Wireless sensors network in Avionic control systemUniversity of Gujrat, Pakistan
 
Hardware implementation of cots avionics system on unmanned
Hardware implementation of cots avionics system on unmannedHardware implementation of cots avionics system on unmanned
Hardware implementation of cots avionics system on unmannedUniversity of Gujrat, Pakistan
 
Binary to grey code conversion
Binary to grey code conversionBinary to grey code conversion
Binary to grey code conversionSunny
 
Introduction to Interfacing Technique
Introduction to Interfacing TechniqueIntroduction to Interfacing Technique
Introduction to Interfacing TechniqueMabeth MaRiyah Ramos
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic   copyChp6 assembly language programming for pic   copy
Chp6 assembly language programming for pic copymkazree
 
Interfacing of 8255 IC By Er. Swapnil Kaware.
Interfacing of 8255 IC By Er. Swapnil Kaware.Interfacing of 8255 IC By Er. Swapnil Kaware.
Interfacing of 8255 IC By Er. Swapnil Kaware.Prof. Swapnil V. Kaware
 

Viewers also liked (20)

8086 microprocessor lab manual
8086 microprocessor lab manual8086 microprocessor lab manual
8086 microprocessor lab manual
 
8086 assembly language
8086 assembly language8086 assembly language
8086 assembly language
 
microprocessor 8086 lab manual !!
microprocessor 8086 lab manual !!microprocessor 8086 lab manual !!
microprocessor 8086 lab manual !!
 
Ascii adjust & decimal adjust
Ascii adjust & decimal adjustAscii adjust & decimal adjust
Ascii adjust & decimal adjust
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5
 
Flags registor of 8086 processor
Flags registor of 8086 processorFlags registor of 8086 processor
Flags registor of 8086 processor
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructions
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
05 multiply divide
05 multiply divide05 multiply divide
05 multiply divide
 
Introduction to 8085 Microprocessor
Introduction to 8085 MicroprocessorIntroduction to 8085 Microprocessor
Introduction to 8085 Microprocessor
 
Wireless sensors network in Avionic control system
Wireless sensors network in Avionic control systemWireless sensors network in Avionic control system
Wireless sensors network in Avionic control system
 
Hardware implementation of cots avionics system on unmanned
Hardware implementation of cots avionics system on unmannedHardware implementation of cots avionics system on unmanned
Hardware implementation of cots avionics system on unmanned
 
An autonomous uav with an optical flow sensor
An autonomous uav with an optical flow sensorAn autonomous uav with an optical flow sensor
An autonomous uav with an optical flow sensor
 
Binary to grey code conversion
Binary to grey code conversionBinary to grey code conversion
Binary to grey code conversion
 
Introduction to Interfacing Technique
Introduction to Interfacing TechniqueIntroduction to Interfacing Technique
Introduction to Interfacing Technique
 
Internal microprocessor architecture
Internal microprocessor architectureInternal microprocessor architecture
Internal microprocessor architecture
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic   copyChp6 assembly language programming for pic   copy
Chp6 assembly language programming for pic copy
 
Probability And Random Variable Lecture 1
Probability And Random Variable Lecture 1Probability And Random Variable Lecture 1
Probability And Random Variable Lecture 1
 
Interfacing of 8255 IC By Er. Swapnil Kaware.
Interfacing of 8255 IC By Er. Swapnil Kaware.Interfacing of 8255 IC By Er. Swapnil Kaware.
Interfacing of 8255 IC By Er. Swapnil Kaware.
 
Dual combustion cycle
Dual combustion cycleDual combustion cycle
Dual combustion cycle
 

Similar to Multiplication & division instructions microprocessor 8086

assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...Bilal Amjad
 
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
 
Chap3 8086 artithmetic
Chap3 8086 artithmeticChap3 8086 artithmetic
Chap3 8086 artithmeticHarshitParkar6677
 
Chapter 3 8086 ins2 math
Chapter 3 8086 ins2 mathChapter 3 8086 ins2 math
Chapter 3 8086 ins2 mathHarshitParkar6677
 
Mastering Assembly Language: Programming with 8086
Mastering Assembly Language: Programming with 8086Mastering Assembly Language: Programming with 8086
Mastering Assembly Language: Programming with 8086sravanithonta79
 
Arithmetic instrctions
Arithmetic instrctionsArithmetic instrctions
Arithmetic instrctionsHarshitParkar6677
 
Traduccion a ensamblador
Traduccion a ensambladorTraduccion a ensamblador
Traduccion a ensambladortre_na_gil
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction setmengistu ketema
 
Microprocssor
MicroprocssorMicroprocssor
Microprocssorriyadh8
 
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
 
8086 arch instns
8086 arch instns8086 arch instns
8086 arch instnsRam Babu
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086Vijay Kumar
 

Similar to Multiplication & division instructions microprocessor 8086 (20)

assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
 
Al2ed chapter11
Al2ed chapter11Al2ed chapter11
Al2ed chapter11
 
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
 
Chap3 8086 artithmetic
Chap3 8086 artithmeticChap3 8086 artithmetic
Chap3 8086 artithmetic
 
8086 ins2 math
8086 ins2 math8086 ins2 math
8086 ins2 math
 
Chapter 3 8086 ins2 math
Chapter 3 8086 ins2 mathChapter 3 8086 ins2 math
Chapter 3 8086 ins2 math
 
Mastering Assembly Language: Programming with 8086
Mastering Assembly Language: Programming with 8086Mastering Assembly Language: Programming with 8086
Mastering Assembly Language: Programming with 8086
 
Arithmetic instrctions
Arithmetic instrctionsArithmetic instrctions
Arithmetic instrctions
 
Traduccion a ensamblador
Traduccion a ensambladorTraduccion a ensamblador
Traduccion a ensamblador
 
Instruction formats-in-8086
Instruction formats-in-8086Instruction formats-in-8086
Instruction formats-in-8086
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
 
Microprocssor
MicroprocssorMicroprocssor
Microprocssor
 
[ASM]Lab4
[ASM]Lab4[ASM]Lab4
[ASM]Lab4
 
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
 
Module 2 (1).pptx
Module 2 (1).pptxModule 2 (1).pptx
Module 2 (1).pptx
 
Bcd arithmetic instructions
Bcd arithmetic instructionsBcd arithmetic instructions
Bcd arithmetic instructions
 
8086 arch instns
8086 arch instns8086 arch instns
8086 arch instns
 
Mod-2.pptx
Mod-2.pptxMod-2.pptx
Mod-2.pptx
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 

More from University of Gujrat, Pakistan

Constitutional development of pakistan since 1947 to thereayf
Constitutional development of pakistan since 1947 to thereayfConstitutional development of pakistan since 1947 to thereayf
Constitutional development of pakistan since 1947 to thereayfUniversity of Gujrat, Pakistan
 
Passive Thermal management for avionics in high temperature environment
Passive Thermal management for avionics in high temperature environmentPassive Thermal management for avionics in high temperature environment
Passive Thermal management for avionics in high temperature environmentUniversity of Gujrat, Pakistan
 
Future Integrated Systems Concept for Preventing Aircraft Loss-of-Control (L...
Future Integrated Systems Concept for Preventing Aircraft Loss-of-Control (L...Future Integrated Systems Concept for Preventing Aircraft Loss-of-Control (L...
Future Integrated Systems Concept for Preventing Aircraft Loss-of-Control (L...University of Gujrat, Pakistan
 
A wireless sensors network in Aircraft Control Systems
A wireless sensors network in Aircraft Control SystemsA wireless sensors network in Aircraft Control Systems
A wireless sensors network in Aircraft Control SystemsUniversity of Gujrat, Pakistan
 
Towards Automating Interface Control Documents Elaboration and Management
Towards Automating Interface Control Documents Elaboration and ManagementTowards Automating Interface Control Documents Elaboration and Management
Towards Automating Interface Control Documents Elaboration and ManagementUniversity of Gujrat, Pakistan
 
APPLICATION OF WIRELESS SENSOR NETWORKS TO AIRCRAFT CONTROL AND HEALTH MANAGE...
APPLICATION OF WIRELESS SENSOR NETWORKS TO AIRCRAFT CONTROL AND HEALTH MANAGE...APPLICATION OF WIRELESS SENSOR NETWORKS TO AIRCRAFT CONTROL AND HEALTH MANAGE...
APPLICATION OF WIRELESS SENSOR NETWORKS TO AIRCRAFT CONTROL AND HEALTH MANAGE...University of Gujrat, Pakistan
 
AVIONIC CONTROL SYSTEMS FOR EDUCATION & DEVELOPMENT
AVIONIC CONTROL SYSTEMS FOR EDUCATION & DEVELOPMENTAVIONIC CONTROL SYSTEMS FOR EDUCATION & DEVELOPMENT
AVIONIC CONTROL SYSTEMS FOR EDUCATION & DEVELOPMENTUniversity of Gujrat, Pakistan
 

More from University of Gujrat, Pakistan (20)

Natural disasters of pakistan
Natural disasters of pakistanNatural disasters of pakistan
Natural disasters of pakistan
 
Diesel cycle
Diesel cycleDiesel cycle
Diesel cycle
 
Carnot cycle
Carnot cycleCarnot cycle
Carnot cycle
 
Brayton cycle
Brayton cycleBrayton cycle
Brayton cycle
 
Constitutional development of pakistan since 1947 to thereayf
Constitutional development of pakistan since 1947 to thereayfConstitutional development of pakistan since 1947 to thereayf
Constitutional development of pakistan since 1947 to thereayf
 
Essay writing
Essay writingEssay writing
Essay writing
 
Letter writing (Communication Skills)
Letter writing (Communication Skills)Letter writing (Communication Skills)
Letter writing (Communication Skills)
 
Architecture of high end processors
Architecture of high end processorsArchitecture of high end processors
Architecture of high end processors
 
Architecture of pentium family
Architecture of pentium familyArchitecture of pentium family
Architecture of pentium family
 
Bus interface 8086
Bus interface 8086Bus interface 8086
Bus interface 8086
 
Protected mode memory addressing 8086
Protected mode memory addressing 8086Protected mode memory addressing 8086
Protected mode memory addressing 8086
 
Passive Thermal management for avionics in high temperature environment
Passive Thermal management for avionics in high temperature environmentPassive Thermal management for avionics in high temperature environment
Passive Thermal management for avionics in high temperature environment
 
Future Integrated Systems Concept for Preventing Aircraft Loss-of-Control (L...
Future Integrated Systems Concept for Preventing Aircraft Loss-of-Control (L...Future Integrated Systems Concept for Preventing Aircraft Loss-of-Control (L...
Future Integrated Systems Concept for Preventing Aircraft Loss-of-Control (L...
 
A wireless sensors network in Aircraft Control Systems
A wireless sensors network in Aircraft Control SystemsA wireless sensors network in Aircraft Control Systems
A wireless sensors network in Aircraft Control Systems
 
Helicopter Automation Using Low Cost Sensors
Helicopter Automation Using Low Cost SensorsHelicopter Automation Using Low Cost Sensors
Helicopter Automation Using Low Cost Sensors
 
Towards Automating Interface Control Documents Elaboration and Management
Towards Automating Interface Control Documents Elaboration and ManagementTowards Automating Interface Control Documents Elaboration and Management
Towards Automating Interface Control Documents Elaboration and Management
 
APPLICATION OF WIRELESS SENSOR NETWORKS TO AIRCRAFT CONTROL AND HEALTH MANAGE...
APPLICATION OF WIRELESS SENSOR NETWORKS TO AIRCRAFT CONTROL AND HEALTH MANAGE...APPLICATION OF WIRELESS SENSOR NETWORKS TO AIRCRAFT CONTROL AND HEALTH MANAGE...
APPLICATION OF WIRELESS SENSOR NETWORKS TO AIRCRAFT CONTROL AND HEALTH MANAGE...
 
AVIONIC CONTROL SYSTEMS FOR EDUCATION & DEVELOPMENT
AVIONIC CONTROL SYSTEMS FOR EDUCATION & DEVELOPMENTAVIONIC CONTROL SYSTEMS FOR EDUCATION & DEVELOPMENT
AVIONIC CONTROL SYSTEMS FOR EDUCATION & DEVELOPMENT
 
Flight control and system 100
Flight control and system 100Flight control and system 100
Flight control and system 100
 
Helicopter automation using low cost sensors
Helicopter automation using low cost sensorsHelicopter automation using low cost sensors
Helicopter automation using low cost sensors
 

Recently uploaded

main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxPurva Nikam
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Study on Air-Water & Water-Water Heat Exchange in a Finned īģŋTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned īģŋTube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned īģŋTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned īģŋTube ExchangerAnamika Sarkar
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 

Recently uploaded (20)

main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptx
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Study on Air-Water & Water-Water Heat Exchange in a Finned īģŋTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned īģŋTube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned īģŋTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned īģŋTube Exchanger
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 

Multiplication & division instructions microprocessor 8086

  • 1.
  • 2. TOPIC: MULTIPLICATI ON AND DIVISION Group member: M Hamza Nasir (12063122-067) M Usaman Ali (12063122-086) Syed Farhan Abbas (12063122-009) M Faran Ali (12063122-055) Ateeb Saeed (12063122-094) University Of Gujrat
  • 4. MUL INSTRUCTION (UNSIGNED MULTIPLY) Multiplies an 8-, 16-, or 32-bit operand by either AL, AX Syntax:MUL AL R/M8 Syntax: MUL AX R/M16
  • 5. MUL INSTRUCTION īƒ˜Note that the product is stored in a register (or group of registers) twice the size of the operands. īƒ˜The operand can be a register or a memory operand
  • 7. MUL EXAMPLES Mov al, 5h Mov bl, 10h Mul bl ; AX = 0050h, CF = 0 īƒ˜ No overflow - the Carry flag is 0 because the upper half of AX is zero
  • 8. IMUL INSTRUCTION (SIGNED MULTIPLY) īƒ˜same syntax īƒ˜uses the same operands as the MUL instruction īƒ˜ preserves the sign of the product īƒ˜Opcode=IMUL
  • 9. IMUL INSTRUCTION īƒ˜Suppose AX contains 1 and BX contains FFFFh Mov AX, 1h Mov BX, FFFFh IMUL BX ; Decimal product=-1, Hex Product =FFFFFFFFh DX = FFFFh, AX=FFFFh CF/OF=0 DX is a sign extension of AX for this CF/OF=0
  • 10. IMUL INSTRUCTION īƒ˜IMUL sets the Carry and Overflow flags if the high-order product is not a sign extension of the low-order product Mov al, 48 Mov bl, 4 Imul bl ;AX = 00C0h, OF = 1 AH is not a sign extension of AL, so the Overflow flag is set
  • 11. IMUL INSTRUCTION Suppose AX contains FFFFh and BX contains FFFFh Mov AX, FFFFH Mov BX, FFFFh IMUL BX Decimal product=1 Hex Product = 00000001 h DX = 0000h, AX=0001h CF/OF=0 DX is a sign extension of AX for this CF/OF=0
  • 12. IMUL INSTRUCTION īƒ˜Suppose AX contains 0FFFh.and BX contains 0FFFh Mov AX, 0FFFH Mov BX, 0FFFh IMUL BX Decimal product=16769025 Hex Product = 00FFE001 h DX = 00FFh, AX=E001h CF/OF=0 DX is a not sign extension of AX for this CF/OF=1
  • 13. IMUL INSTRUCTION īƒ˜Suppose AL contains 80h.and BL contains FFh Mov AL, 80H Mov BL, FFh IMUL BL Decimal product=128, Hex Product = 0080 h AH = 00h, AL=80h CF/OF=01 DX is a not sign extension of AX for this CF/OF=1
  • 14. APPLICATION OF MUL AND IMUL īƒ˜Translate the high level language assignment statement īƒ˜A=5×A-12×B īƒ˜Let A and B be word variables, and suppose there is no overflow. īƒ˜Use IMUL for multiplication
  • 15. SOLUTION: īƒ˜Mov AX,5 ;AX=5 īƒ˜IMUL A ;AX=5*A īƒ˜MOV A,AX ;A=5*A īƒ˜MOV AX,12 ;AX=12 īƒ˜IMUL B ;AX=12*B īƒ˜SUB A,AX ;5*A-12*B
  • 17. DIVIDE AND IDIVIDE īƒ˜When division is performed we obtain two results īƒ˜The quotient and īƒ˜The remainder. īƒ˜Similarly like Multiplication there are separate instructions for unsigned and signed division
  • 18. CONT.. Syntax: DIV divisor IDIV divisor Byte Form: The divisor is eight bit register or memory byte The 16 – bit dividend is assumed to be in AX. After division 8-bit quotient is in AL and 8-bit remainder in AH.
  • 19. CONT.. Word Form: The divisor is a 16-bit register or memory word The 32-bit dividend is assumed to be in DX:AX After division, the 16-bit quotient is in AX and 16- bit remainder is in DX Effect on flags: All status flags are undefined
  • 20. CONT.. Divide Overflow: īƒ˜It is possible that the quotient s too big to fit in the specified destination(AL or AX). īƒ˜This Happens Because the divisor is much smaller than the dividend. īƒ˜When this Happens the program terminates and system displays message “divide overflow”
  • 21. CONT.. Examples: EXAMPLE 9.8: Suppose DX contains 0000h , AX contains 0005h, and BX contains 0002h. EXAMPLE 9.9: Suppose DX contains 0000h , AX contains 0005h and BX contains FFFEh. EXAmple 9.10: Suppose AX contains 00FBh and BL contains FFh.
  • 22. DECIMAL INPUT AND OUTPUT īƒ˜Computer represent every thing in binary īƒ˜But it is convenient for user to represent input and output in decimal īƒ˜If we input 21543 character string then it must to converted internally īƒ˜Conversely on output the binary contents of R/M must be converted to decimal equivalent before being printed
  • 23. DECIMAL INPUT īƒ˜Convert a string of ASCII digits to the binary representation of decimal equivalent īƒ˜For input we repeatedly multiply AX by 10 Algorithm (First version): Total=0 Read an ASCII REPEAT convert character to number Total=total*10+value Read a character Until character is carriage return
  • 24. CONT.. Example: input of 123 Total =0 Read ‘1’ Convert ‘1’ to 1 Total=10*0 +1=1 Read ‘2’ Convert ‘2’ to 2 Total=10*1 +2=12 Read ‘3’ Convert ‘3’ to 3 Total=10*12 +3=123
  • 25. CONT.. īƒ˜Range: -32768 to 32767 īƒ˜Optional sign followed by string of digits & carriage return īƒ˜Outside ‘0’ to ‘9’ īƒ˜jumps to new line and ask for input again
  • 26. CONT.. Algorithm(second version): total=0 Negative=false Read a character Case character of â€ĸ ‘-’: negative=true read a character â€ĸ ‘+’: read a character End_case Repeat If character is not between ‘0’ to ‘9’ Then Go to beginning
  • 27. CONT.. Else Convert character to binary value Total=10*total+value End_if Read a character Until character is carriage return If negative =true Then total=-total
  • 28. CONT.. Program(source code): INDEC PROC ;READ NUMBER IN RANGE -32768 TO 32767 PUSH BX PUSH CX PUSH DX @BEGIN: ;total =0 XOR BX,BX ;BX hold total ;negative =false
  • 29. CONT.. XOR CX,CX ;CX hold sign ;read char MOV AH,1 INT 21H ;case char of CMP AL,'-' ;minus sign JE @MINUS ;yes,set sign CMP AL,'+' ;plus sign JE @PLUS ;yes,get another char
  • 30. CONT.. JMP @REPEAT2 ;start processing char @MINUS: MOV CX,1 @PLUS: INT 21H ;end case @REPEAT2: ;if char. is between '0' and '9' CMP AL,'0' ;char >='0'? JNGE @NOT_DIGIT ;illegal char.
  • 31. CONT.. CMP AL,'9' ;char<='9' ? JNLE @NOT_DIGIT ;then convert char to digit AND AX,000FH PUSH AX ;save number ;total =total *10 +digit MOV AX,10 MUL BX POP BX ;retrieve number ADD BX,AX ;total =total *10 +digit
  • 32. CONT.. ;read char MOV AH,1 INT 21H CMP AL,0DH ;CR JNE @REPEAT2 ;no keep going ;until CR MOV AX,BX ;store number in AX ;if negative OR CX,CX ;negative
  • 33. CONT.. Jz @EXIT ;no,exit ;then NEG AX ;yes,negate ;end if @EXIT: ;retrieve registers POP DX POP CX POP BX RET
  • 34. CONT.. ;here if illegal char entered @NOT_DIGIT: MOV AH,2 MOV DL,0DH INT 21H MOV DL,0AH INT 21H JMP @BEGIN INDEC ENDP
  • 36. INPUT OVERFLOW īƒ˜AX:FFFFh īƒ˜In decimal:65535 īƒ˜Range:-32768 to 32767 īƒ˜Anything out of range called input overflow īƒ˜For example: īƒ˜Input:32769 īƒ˜Total=327690
  • 37. CONT.. Algorithm: total=0 Negative=false Read a character Case character of â€ĸ ‘-’: negative=true read a character â€ĸ ‘+’: read a character
  • 38. CONT.. End_case Repeat If character is not between ‘0’ to ‘9’ Then Go to beginning Else Convert character to binary value Total=10*total
  • 39. CONT.. If overflow Then go to beginning Else Total =total*10 +value If overflow Then go to beginning
  • 40. CONT.. End_if End_if End_if Read a character Until character is carriage return If negative =true Then total=-total
  • 41. CONT.. Code: ;total =total *10 +digit MOV AX,10 MUL BX CMP DX,0 JNE @NOT_DIGIT POP BX ADD BX,AX JC @NOT_DIGIT
  • 43. Decimal Output Algorithm for Decimal Output: īƒ˜If AX < 0 /*AX holds output value */ īƒ˜THEN īƒ˜Print a minus sign īƒ˜Replace AX by its twos complement īƒ˜End_IF īƒ˜Get the digits in AX’s decimal representation īƒ˜Convert these digits into characters and print them
  • 44. CONT.. To see what line 6 entitles, suppose the contents of AX, expressed in decimal is 24168. To get the digits in decimal representation , we can proceed as follows, īƒ˜Divide 24618 by 10, Quotient= 2461, remainder=8 īƒ˜Divide 2461 by 10, Quotient= 246, remainder=1 īƒ˜Divide 246 by 10 , Quotient=24, remainder=6 īƒ˜Divide 24 by 10, Quotient=2, remainder=4 īƒ˜Divide 2 by 10, Quotient=0, remainder=2
  • 45. CONT.. LINE 6: Cout =0 /*will count decimal digit */ REPEAT divide quotient by 10 Push remainder on the stack Count= count +1 UNTILL Quotient=0
  • 46. CONT.. LINE 7: FOR count times DO Pop a digit from the stack Convert it to a character Output the character END_FOR
  • 47. CONT.. Program Listing PMG9_1.ASM .MODEL SMALL .STACK 100H .CODE OUTDEC PROC ;prints AX as a signed decimal integer ;input: AX ;output: none PUSH AX ;save registers PUSH BX PUSH CX PUSH DX
  • 48. CONT.. ;if AX < 0 OR AX,AX ;AX < 0? JGE @END_IF1 ;NO >0 ;then PUSH AX ; save number MOV DL,’-’ ;get ‘-’ MOV AH,2 ;print character function INT 21H ;print ‘-’ POP AX ;get Ax back NEG AX ;AX= -AX @END_IF1:
  • 49. CONT.. ;get decimal digits XOR CX,CX ;CX counts digits MOV BX,10D ;BX has divisor @REPEAT1: XOR DX,DX ;prepare high word of dividend DIV BX ;AX=quotient, DX=remainder PUSH DX ;save remainder on stack INC CX ;count = count +1 ;until OR AX,AX ;quotient = 0? JNE @REPEAT ;no, keep going
  • 50. CONT.. ;convert digits to character and print MOV AH,2 ;print character function ;for count time do @PRINT_LOOP POP DX ;digit in DL OR DL,30H ;convert to character INT 21H ;print digit ;end_for POP DX ; restore registers POP CX POP BX POP AX OUTDEC ENDP