Professional Documents
Culture Documents
y Numbersystemsandbasicarithmeticoperations y Unconventionalfixedpointnumbersystems y Sequential q algorithms g formultiplication p anddivision y Floatingpointarithmetic y Algorithms Al ith for f fast f taddition dditi y Highspeedmultiplication
TheBinaryNumberSystem
y Inconventionaldigitalcomputers integers
representedasbinarynumbersoffixedlengthn y Anorderedsequence(xn1, xn2,, x1, xo)ofbinarydigits y Eachdigitxi (bit)is0 or1 y The h above b sequencerepresentsthe h integervalue l X
X = x n 1 2
n 1
+ x n 2 2
n 2
+ ... + x 1 2 + x 0 = x i 2i
i =1
n 1
RadixofaNumberSystem
y Theweightofthedigitxi isthei th powerof2 y 2istheradix ofthebinarynumbersystem y Binary Bi numbers b areradix di 2 numbers b allowed ll ddi digits i are
RangeofRepresentations
y Operandsandresultsarestoredinregistersoffixed
lengthn finitenumberofdistinctvaluesthatcan berepresentedwithinanarithmeticunit y Xmin ;Xmax smallestandlargestrepresentable values y [Xmin,Xmax] range oftherepresentablenumbers y AresultlargerthenXmax orsmallerthanXmin incorrectlyrepresented y Thearithmeticunitshouldindicatethatthe generatedresultisinerror anoverflow indication
Example OverflowinBinarySystem
y Unsignedintegerswith5 binarydigits(bits) y Xmax = (31)10 =(11111)2 Xmin = (0)10 =(00000)2 y IncreasingXmax by1 =(32)10=(100000)2 y 5bit representation t ti yielding i ldi (00000) ( )2=(0) ( )10 y Ingeneral y Anumber b X notin i the h range[Xmin,Xmax]=[0,31] ] [ ]is i representedbyX mod32 y IfX+Y X Y exceeds d Xmax the th result ltis i S =(X+Y)mod d32 y Example: X 1000117
+Y 1001018 1 000113=35mod32
y Result l has h tobe b stored dina5bit b register the h most
significantbit(withweight25 =32)isdiscarded
MachineRepresentationsofNumbers
y Binarysystem oneexampleofanumbersystemthat
canbeusedtorepresentnumericalvaluesinan arithmeticunit y Anumbersystem isdefinedbythesetofvaluesthat eachdigitcanassumeandbyaninterpretationrule thatdefinesthemappingbetweenthesequencesof di i and digits dtheir h i numerical i lvalues l y Typesofnumbersystems y conventional (e.g.,binary,decimal) y unconventional (e.g., g signed g digit g numbersystem) y
ConventionalNumberSystems
y Propertiesofconventionalnumbersystems: y Nonredundant y Everynumberhasauniquerepresentation,thus y Notwosequenceshave h the h samenumerical i lvalue l y Weighted y Asequenceof fweights i h wn1,wn2,...,w1,w0 determines d i thevalueofthentuple xn1,xn2,...,x1,x0 by
X = x iw i
i =1 n 1
radix systems y Withnoredundancy 0 xi r1 y xi r introduces i t d redundancy d d i into t th thefi fixed dradix di numbersystem y Ifxi r isallowed
x i r = (x i r )r + 1.r
i i
i +1
y twomachinerepresentationsforthesamevalue
( xi+1,xi,...)and (...,
representinganinteger y Canrepresent p amixednumberwithafractionalpart p andanintegralpart y Then digitsarepartitionedintotwo k inthe integralpartandm inthefractionalpart(k+m=n) y Thevalueofanntuplewitharadixpointbetweenthe k mostsignificantdigitsandthemleastsignificant digits g
y is
X = x k 1r
k 1
+ x k 2 r
k 2
+ ... + x 1r + x 0 + x 1r + ... + x m r
i = m
k 1
xiri
FixedPointRepresentations
y Radixp pointnotstoredinregister g understoodtobeina
y Programmernotrestrictedtothepredeterminedposition
oftheradixp point
y Operandscanbescaled samescalingforalloperands
y Addandsubtractoperationsarecorrect y aX aY=a(X Y) (a scalingfactor) y Correctionsrequiredformultiplicationanddivision y aX X aY=a Y 2 X Y;aX/aY=X/Y X/ Y X/Y y Commonlyusedpositionsfortheradixpoint y rightmostsideofthenumber(pureintegers m=0) m 0) y leftmostsideofthenumber(purefractions k=0)
ULP UnitinLastPosition
y Giventhelengthn oftheoperands,theweightrm
oftheleastsignificantdigitindicatestheposition oftheradixpoint y Unitinthelastposition(ulp) theweightofthe leastsignificantdigit y ulp =rm y Thisnotationsimplifiesthediscussion y Noneedtodistinguishbetweenthedifferent partitionsofnumbersintofractionalandintegral parts
y Radixconversion Integer andFractional
RepresentationofNegativeNumbers
y Fixedpointnumbersinaradixr system y Twoways y ofrepresenting p gnegative g numbers: y Signandmagnitude representation (orsigned
SignedMagnitudeRepresentation
y Signandmagnitudearerepresentedseparately y Firstdigitisthesigndigit,remainingn1 digits y y y y
represent ep ese tthe t emagnitude ag tude Binarycase signbitis0 forpositive,1fornegative numbers Nonbinarycase 0 andr1 indicatepositiveand negativenumbers Only2.rn1 outofthern possiblesequencesareutilized Tworepresentations p forzero p positiveandnegative g
y Inconvenientwhenimplementinganarithmeticunit
DisadvantageoftheSignedMagnitudeRepresentation
yO Operation ti maydepend d donthe th signs i of fthe th operands d y Example addingapositivenumberX andanegative
ComplementRepresentationsofNegativeNumbers
y Twoalternatives y Radixcomplement(calledtwo two's scomplementinthe binarysystem) y Diminishedradixcomplement(calledone'scomplement inthebinarysystem) y Inbothcomplementmethods positivenumbers
represented t dasin i the th signed i dmagnitude it d method th d y AnegativenumberY isrepresentedbyRY whereR isa constant y Thisrepresentationsatisfies(Y)=Y sinceR(RY)=Y
AdvantageofComplementRepresentation
y Nodecisionsmadebeforeexecutingadditionor
additionalR mustbediscarded y Rse selected ectedtos simplify p yo oreliminate e atethis t scorrection co ect o y Anotherrequirement calculationofthecomplementR Y shouldbesimpleanddoneathighspeed y Definitions:
y Complementofasingledigitxi
SelectingRinRadixComplementRep. Rep
y y y
y y y y
X + X + ulp p = rk Resultstoredintoaregister oflength g n(=k+m) Mostsignificantdigitdiscarded finalresultiszero Ingeneral,storingtheresultofanyarithmeticoperationinto afixed f dlength l hregisterisequivalent l totaking k the h remainder d afterdividingbyrk r k X = X + ulp l SelectingR=rk : R X=rk X=X+ulp CalculationofRX simpleandindependentofk Thisisradixcomplementrepresentation R=rk discardedwhencalculatingR+(XY) nocorrection neededwhenX+(RY) ispositive(X>Y)
y Eachpositivenumberhasacorrespondingnegativenumber
that th tstarts t t with itha1 y 1000 representing(8)10 hasnocorrespondingpositive number y Rangeofrepresentable numbersis8 X 7
Example AdditioninTwoscomplement
y CalculatingX+(Y) withY>X
3+(5) 00113 + 10115 11102 y Correct C tresult ltrepresented t d i inth thetwo's t ' complement l tmethod th d noneedforpreliminarydecisionsorpostcorrections y Calculating C l l i X+( X (Y) with i hX>Y X Y 5+( (3) ) 01015 + 1101 3 1 00102 y Onlythelastfourleastsignificantdigitsareretained, yielding0010
Example OnesComplementinBinarySystem
y r=2,k=n=4,m=0,ulp=20 =1 y Diminishedradixcomplement p (called ( one'scomplement p y y y y
inthebinarycase)ofanumberX =(241) X= X Asbefore, ,thesequences q 0000 to0111 represent p the positivenumbers010 to710 Theone one's scomplementof0111 is1000,representing(7)10 Theone'scomplementofzero is1111 two representationsofzero Rangeofrepresentable numbersis7 X 7
ComparingtheThreeRepresentationsinaBinarySystem
Example:RadixComplementDecimalSystem
y Leadingdigit0,1,2,3,4 positive y Leadingdigit5,6,7,8,9 negative y Example n=4 y 0000 to4999 positive y 5000 000 to9999 negative negati e (5000) 000)to 1 y Range 5000 X 4999 y Y=1234 34 y RepresentationofY=1234 y y y y
radixcomplementRY withR=104 RY= Y +ulp Digitcomplement=9 digit ;ulp=1 8765; 8766 representationof Y Y +1=8766 Y =8765 Y+(Y)=1234+8766=104 =0mod104
2n1
NumericalValueofaTwosComplementRepresentation
y NumericalvalueXofrepresentation(xn1,xn2,...,x0) in
bycomplementingthesequence(i.e.,complementing eachbitandadding1)andaddingaminussign y Example Giventhe4tuple1010 negative complementing 0101+1=0110 valueis 6 original sequenceis 6
DifferentCalculationofNumericalValue
X = x n 1.2
n 1
+ x i 2i
i =0
n 2
complement
X = x n 1.(2 (2
n 1
ulp ) + x i 2i
i =0
n 2
subtractoperation y Acarryoutisnotnecessarilyanindicationofanoverflow
Addition/SubtractioninComplementMethods
y Example (twos E l (t complement) l t)
010019 11001 7 1 000102
y Carryoutdiscarded doesnotindicateoverflow
y Ingeneral,ifX andYhaveoppositesigns no
y Carryoutandoverflow
010019 001117 0 1000016=16mod32 y Nocarry youtbutoverflow
Addition/Subtraction OnesComplement
y y y y y y y
Carryout indicatestheneedforacorrectionstep Example addingpositiveX andnegativeY X+(2n ulp )Y=(2 (2n ulp)+(XY) IfX>Y correctresultisXY 2n represents p thecarry youtbit discardedinaregister g oflength g n ResultisXYulp correctedbyaddingulp Example 010019 + 110007
1 00001 p Correction 1ulp 000102
y Thegeneratedcarryoutiscalledendaroundcarry itisan
indicationthata1 shouldbeaddedtotheleastsignificantposition
Subtraction
y In I b both hcomplement l systems subtract b operation, i XY, Y
X Y = X +Y
y Inthetwo'scomplementsystem
X Y = X + (Y + ulp p)
y Thisstillrequiresonlyasingleadderoperation,since
representationsofnegativenumbers theinfinite extensions t i t toth theright i htand dleft l ftof fagiven i number b
y Signedmagnitudemethod themagnitudexn2,..., x0 can
b viewed be i dasthe h i infinite fi i sequence ,0,0,{xn2,...,x0},0,0,... y Radixcomplementscheme theinfiniteextensionis ,xn1,xn1,{xn1,...,x0},0,0, (xn1 thesigndigit) y Diminishedradixcomplementscheme thesequenceis , ,xn1,xn1,{xn1, ,..., ,x0},xn1,xn1, ,
complement 1001.,11001.1,111001.11 allrepresent 6 inone one's s complement Usefulwhenadding goperands p withdifferentnumbersof bits shorterextendedtolonger Rulesforarithmeticshiftoperations:leftandrightshift areequivalenttomultiplyanddivideby2,respectively TwoscomplementOnescomplement