You are on page 1of 30

S ti l M lti li ti SequentialMultiplication

X,A multiplierandmultiplicand
X=xn1xn2...x0 ;A=an1an2...a1a0
xn 1 an 1 signdigits(signmagnitudeorcomplement xn1,an1 signdigits(signmagnitudeorcomplement
methods)
Sequentialalgorithm n 1 steps Sequentialalgorithm n1 steps
Stepj multiplierbitxj examined;productxjA addedto
P
(j)
previouslyaccumulatedpartialproduct(P
(0)
0) P
(j)
previouslyaccumulatedpartialproduct(P
(0)
=0)
l l b h f b h h Multiplyingby2
1
shiftbyonepositiontotheright
alignmentnecessarysincetheweightofxj+1 isdouble
h f thatofxj
S ti l M lti li ti P f SequentialMultiplication Proof
Repeatedsubstitution Repeatedsubstitution
-(n-1)
=2
Ifbothoperandspositive(xn 1 an 1 0) Ifbothoperandspositive(xn1=an1=0)
Theresultisaproductconsistingof2(n 1) bitsforits Theresultisaproductconsistingof2(n1) bitsforits
magnitude
Number of product bits Numberofproductbits
M i l fU h A dX i l MaximumvalueofU whenA andX aremaximal
Lasttermpositiveforn3,therefore
2n2 bitsrequiredtorepresentthevalue
2n1 bitswiththesignbit g
Signedmagnitudenumbers multiplytwo
magnitudesandgeneratethesignseparately g g g p y
(positiveifbothoperandshavethesamesignand
negativeotherwise) g
Negativeoperands
Fortwo'sandone'scomplement distinguish
betweenmultiplicationwithanegative
l i li dA d l i li i i h i multiplicandA andmultiplicationwithanegative
multiplierX
If l l i li di i d h Ifonlymultiplicandisnegative noneedtochange
thepreviousalgorithm onlyaddsomemultipleof
ti b th ti t di ith anegativenumberthatisrepresentedineither
two'sorone'scomplement
Multiplication Example Multiplication Example
A negative,two'scomplement,X positive,4 bits
Product 7 bits includingsignbit Product 7 bits,includingsignbit
Registersare4bitslong adoublelengthregister
requiredforstoringthefinalproduct equ ed o sto g t e a p oduct
Verticallineseparatesmostfromleastsignificanthalf
eachstoredinasinglelengthregister g g g
Bitsinleastsignificanthalfnotusedintheaddoperation
Least significant half of product Leastsignificanthalfofproduct
Only3bitpositionsareutilized leastsignificantbitposition Only3bitpositionsareutilized leastsignificantbitposition
unused notnecessarilyfinalarrangement
The3bitscanbestoredin3rightmostpositions
Signbitofsecondregistercanbesetintwoways
(1)Alwayssetsignbitto0,irrespectiveofsignoftheproduct,
i iti th l t i ifi t t f lt sinceitistheleastsignificantpartofresult
(2)Setsignbitequaltosignbitoffirstregister
Anotherpossiblearrangement Anotherpossiblearrangement
Useallfourbitpositionsinsecondregisterforthefourleast
significantbitsoftheproduct
Usetherightmosttwobitpositionsinthefirstregister
Inserttwocopiesofsignbitintoremainingbitpositions
Negative Multiplier Twos Complement NegativeMultiplier Two sComplement
Eachbitconsideredseparately signbit(withnegative
i h ) ddiff l h h bi weight)treateddifferentlythanotherbits
Two'scomplementnumbers
;;
Ifsignbitofmultiplierisignored
X A i h d i d d if i i XA isthedesiredproduct ifxn1=1 acorrectionis
necessary
ThemultiplicandAissubtracted fromthemost
significanthalfofU significanthalfofU
N ti M lti li E l NegativeMultiplier Example
Multiplierandmultiplicand negativenumbersin Multiplierandmultiplicand negativenumbersin
two'scomplement
Incorrectionstep,subtractionofmultiplicandis p, p
performedbyaddingitstwo'scomplement
NegativeMultiplier OnesComplement
d and
Ifxn1=1,startwithP
(0)
=A thistakescareofthe
secondcorrectiontermxn1 ulp A
Attheendoftheprocess subtractthefirstcorrection p
term xn1 2
(n1)
A
Negative Multiplier Example NegativeMultiplier Example
Productof5and3 one'scomplement
Asinpreviousexample subtractionoffirstcorrectionterm
addingitsone'scomplement g p
Unlikepreviousexample one'scomplementhastobe
expandedtodoublesizeusingthesigndigit adoublelength
binaryadderisneeded binaryadderisneeded
Sequential Division SequentialDivision
Division themostcomplexandtime consumingof Division themostcomplexandtimeconsumingof
thefourbasicarithmeticoperations
Ingeneral resultofdivisionhastwocomponents Ingeneral,resultofdivisionhastwocomponents
GivenadividendX andadivisorD,generatea
quotientQ andaremainderR suchthat q Q
X=Q D+R (withR<D)
Assumption X,D,Q,R positive p , ,Q, p
Ifadoublelengthproductisavailableaftera
multiplyandwewishtoallowtheuseofthisresultin p y
asubsequentdivide,then
X mayoccupyadoublelengthregister,whileall
h d di i l l h i otheroperandsstoredinsinglelengthregisters
Overflow&Dividebyzero
Q largestnumberstoredinasinglelengthregister
( f h b ) (<2
n1
foraregisterwithn bits)
1. X<2
n1
D otherwiseanoverflow indicationmust
beproducedbyarithmeticunit
ConditioncanbesatisfiedbypreshiftingeitherX or
D (orboth)
Preshiftingissimplewhenoperandsarefloating
pointnumbers
2. D 0 otherwise adividebyzeroindicationmust
begenerated
NocorrectiveactioncanbetakenwhenD=0
Division Algorithm Fractions DivisionAlgorithm Fractions
Assumption dividend,divisor,quotient,remainderare
f i di id fl di i i X D fractions divideoverflowconditionisX<D
ObtainQ=0.q1 qm (m=n1) sequenceof
subtractionsandshifts
Stepi remainderiscomparedtodivisorD if
remainderlarger quotientbitqi=1,otherwise 0
i
th
step ri = 2ri1qiD;i=1,2,...,m p q ; , , ,
ri isthenewremainderandri1 isthepreviousremainder
(r0=X) (r0=X)
qi determinedbycomparing2ri1 toD themost
complicatedoperationindivisionprocess complicatedoperationindivisionprocess
Di i i Al ith P f DivisionAlgorithm Proof
Theremainderinthelaststepis rm andrepeated
substitutionofthebasicexpressionyields
Substitutingr0=X anddividingbothsidesby2
m
resultsin resultsin
h r
m
X Q D i d hencerm2
m
=X Q D asrequired
TruefinalremainderisR=rm2
m
Di i i E l 1 F ti Division Example1 Fractions
X=(0.100000)2=1/2
D=(0.110)2=3/4
Dividendoccupies
d bl l th doublelengthreg.
X<D satisfied
Generationof2r0 Generationof2r0
nooverflow
Anextrabitpositioninthearithmeticunitneeded Anextrabitpositioninthearithmeticunitneeded
Finalresult:Q=(0.101)2=5/8
R=rm 2
m
=r32
3
=1/4 2
3
=1/32 R rm 2 r32 1/4 2 1/32
Quotientandfinalremaindersatisfy
X=Q D+R=5/8 3/4+1/32=16/32=1/2 Q 5 3 4 3 3
Precisequotientistheinfinitebinaryfraction2/3=0.1010101

l h DivisionAlgorithm Integers
Sameprocedure;Previousequationrewritten Sameprocedure;Previousequationrewritten
(XF,DF,QF,RF fractions) ( , ,Q , )
Dividingby2
2n2
yields
TheconditionX<2
n1
DbecomesXF <DF
X=01000002=32;D=01102=6
OverflowconditionX<2
n1
D istestedbycomparingthe y p g
mostsignificanthalfofX,0100,toD,0110
TheresultsofthedivisionareQ=01012 =5 andR=00102=2
InfinalstepthetrueremainderR isgenerated noneed
tofurthermultiplyitby2
(n1)
RestoringDivision
Comparison most
difficultstepindivision
f If2ri1D<0 qi=0
remainderrestoredtoitspreviousvalue
t i di i i restoringdivision
Robertsondiagram showsthatifri1<D,qi isselectedso
thatri<D thatri<D
Sincer0=X<D R<D
msubtractions mshiftoperations anaverageofm/2 msubtractions,mshiftoperations,anaverageofm/2
restoreoperations
canbedonebyretainingacopyofthepreviousremainder y g py p
avoidingthetimepenalty
N i Di i i R i d Nonrestoring Division Remainder
Alternative quotientbitcorrectionandremainder Alternative quotientbitcorrectionandremainder
restorationpostponedtolatersteps
R i h d if D i d i d Restoringmethod if2ri1D<0 remainderisrestoredto
2ri1
ThenshiftedandD againsubtracted,obtaining4ri1D
processrepeatedaslongasremaindernegative
Nonrestoring restoreoperationavoided
Negativeremainder2ri1D<0 shifted,thencorrectedby g y
addingD,obtaining2(2ri1D)+D=4ri1D
Sameremainderobtainedwithrestoringdivision g
Nonrestoring Division Quotient
Correctingawrongselectionofquotientbitinstepi Correctingawrongselectionofquotientbitinstepi
nextbit,qi+1,canbenegative
If i l i i d
1
Ifqi wasincorrectlysetto1 negativeremainder
selectqi+1= andaddD toremainder
1
Insteadofqiqi+1=10 (toolarge) qi qi+1==01
Furthercorrection ifneeded innextsteps
11
Ruleforqi: Ruleforqi:
Nonrestoring Division Diagram Nonrestoring Division Diagram
Simplerandfasterthanselectionruleforrestoring p g
division 2ri1 comparedto0 insteadoftoD
Sameequationforremainder:ri = 2ri1qiD Sameequationforremainder:ri 2ri 1 qiD
DivisorDsubtractedif2ri1>0 ,addedif<0
|r |<D |ri1|<D
qi selectedso|ri|<D
t h t qi0 ateachstep,
eitheradditionor
bt ti i f d subtractionisperformed
NotSD representationnoredundancyinrepresentation
f ti t ofquotient
Exactlymadd/subtractandshiftoperations
Nonrestoring Division Example 1 Nonrestoring Division Example1
X=(0.100000)2=1/2
( ) D=(0.110)2=3/4
Finalremainder
asbefore
Q=0.111=0.1012=5/8
-
Q 5
Graphicalrepresentation Graphicalrepresentation
Horizontallines
addD addD
Diagonallines
multiplyby2 multiplyby2
Nonrestoring Division Advantage Nonrestoring Division Advantage
Importantfeatureofnonrestoringdivision easily p g y
extendedtotwo'scomplementnegativenumbers
Generalizedselectionruleforqi Generalizedselectionruleforqi
Remainderchangessignsduringprocess nothing
l b d d d specialaboutanegativedividendX
Nonrestoring Division Example 2 Nonrestoring Division Example2
X=(0.100)2=1/2
D=(1.010)2=3/4
Finalquotient
2
2 10
Q 0.111 0.101 0.101 5/8 1.011 = = = = =
intwoscomplement
Finalremainder=1/32 samesignasthedividendX
NonrestoringDivision signofremainder
Signoffinalremainder sameasdividend
Example dividing5 by3 Q=1,R=2,notQ=2,R=1 Example dividing5 by3 Q 1,R 2,notQ 2,R 1
(although|R|<D)
Ifsignoffinalremainderdifferentfromthatof g
dividend correctionneeded resultsfromquotient
digitsbeingrestrictedto1,1
d b "
-
Lastdigitcannotbe0 aneven"quotientcannot
begenerated
N t i Di i i E l 3 Nonrestoring Division Example3
X=0.1102=5/8
D=0.1102=3/4 D 0.1102 3/4
Finalremaindernegative dividendpositive
CorrectfinalremainderbyaddingD tor3 CorrectfinalremainderbyaddingD tor3
1.110+0.110=0.100
Correctquotient Qcorrected =Q ulp Correctquotient Qcorrected Q ulp
Q=0.111 Qcorrected=0.1102=3/4
N t i Di i i C t NonrestoringDivision Cont.
Iffinalremainderanddividendhaveoppositesigns Iffinalremainderanddividendhaveoppositesigns
correctionneeded
Ifdividendanddivisorhavesamesign remainder Ifdividendanddivisorhavesamesign remainder
rm correctedbyaddingD andquotientcorrectedby
subtractingulp g p
Ifdividendanddivisorhaveoppositesigns subtract
D fromrm andcorrectquotientbyaddingulp D fromrm andcorrectquotientbyaddingulp
Anotherconsequenceofthefactthat0 isnotan
alloweddigitinnonrestoringdivision needfor alloweddigitinnon restoringdivision needfor
correctionifa0 remainderisgeneratedinan
intermediatestepp
N t i Di i i E l 4 NonrestoringDivision Example4
X=1.1012=3/8 3/
D=0.1102=3/4
Correctresultof Correctresultof
division
Q / R Q=1/2;R=0
Althoughfinal
remainderanddividendhavesamesign correction
neededduetoazero intermediateremainder
Thismustbedetectedandcorrected
r3(corrected) =r3+D=1.010+0.110=0.000
Correctingthequotientbysubtractingulp:
2
Q 0.111 0.101 = =
corrected 2
Q 0.100 1/ 2 = =
GeneratingaTwo'sComplementQuotientin
Nonrestoring Division NonrestoringDivision
Convertingfromusing1,1 totwo'scomplement
Previousalgorithmsrequirealldigitsofquotient
-
g q g q
beforeconversionstarts increasingexecutiontime
Preferable conversiononthefly seriallyfrommost Preferable conversiononthefly seriallyfrommost
toleastsignificantdigitastheybecomeavailable
Quotientdigitassumestwovalues singlebit Quotientdigitassumestwovalues singlebit
sufficientforrepresentation 0 and1 assignedto
1 and1
-
1 and1
Resultingbinarynumber 0.p1...pm ( pi=1/2(qi+1) )
Conversion Algorithm ConversionAlgorithm
Step1:Shiftnumberonebitpositiontoleft
Step2:Complementmostsignificantbit Step2:Complementmostsignificantbit
Step3:Shifta1intoleastsignificantposition
Result (1p1) p2p3 pm1 hassamenumericalvalueas Result (1p1).p2p3...pm1 hassamenumericalvalueas
originalquotientQ
Proof:Valueofabovesequenceintwo'scomplement q p
Substitutingpi=1/2(qi+1)
Lastterm=2
1
2
m
C i Al i h E l ConversionAlgorithm Example
l h b d b l f h Algorithmcanbeexecutedinabitserialfashion
Example X=1.101;D=0.110
- -
Insteadofgeneratingthequotientbits.111
generatethebits(10).101=1.101
--
Aftercorrectionstep Qulp=1.100 correct
representationof1/2 intwo'scomplement