计算机组成与结构:chapter9 Computer Arithmetic_第1页
计算机组成与结构:chapter9 Computer Arithmetic_第2页
计算机组成与结构:chapter9 Computer Arithmetic_第3页
计算机组成与结构:chapter9 Computer Arithmetic_第4页
计算机组成与结构:chapter9 Computer Arithmetic_第5页
已阅读5页,还剩51页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

ComputerOrganization&ArchitectureChapter9

ComputerArithmetic9.1Arithmetic&LogicUnitDoesthecalculationsEverythingelseinthecomputeristheretoservethisunitController,registers,memory,I/OHandlesintegers,floatingpoint(real)numbersMaybeseparateFPU(mathsco-processor)MaybeonchipseparateFPU(486DX+)ALUInputsandOutputs4.2IntegerRepresentationOnlyhave0&1torepresenteverythingPositivenumbersstoredinbinarye.g.41=00101001NominussignNoperiod(.)n-bitbinarydigitsan-1an-2….a1a0denotesanunsignedintegerASign-MagnitudeRepresentationLeftmostbitissignbit0meanspositive1meansnegative+18=00010010-18=10010010ProblemsNeedtoconsiderbothsignandmagnitudeinarithmeticTworepresentationsofzero(+0and-0)RarelyusedTwo’sComplementRepresentation+3=00000011+2=00000010+1=000000010=00000000-1=11111111-2=11111110-3=11111101Complementofpositivenumber=unsignednumbercomplementofnegativenumber=bitwisenotunsignednumber+1GeometricDepictionofTwosComplementIntegersBenefitsOnerepresentationofzeroArithmeticworkseasily(seelater)Negatingisfairlyeasy3=00000011Booleancomplementgives 11111100Add1toLSBNegationSpecialCase10=00000000Bitwisenot11111111Add1to+1Result100000000Overflowisignored,so:0=0NegationSpecialCase2-128=10000000bitwisenot01111111Add1toLSB+1Result10000000So:-(-128)=-128XMonitorMSB(signbit)ItshouldchangeduringnegationRangeofNumbers8bit2’scomplement+127=01111111=27-1-128=10000000=-2716bit2scomplement+32767=01111111111111111=215-1-32768=10000000000000000=-215ConversionBetweenLengthsPositivenumberpackwithleadingzeros+18=00010010+18=0000000000010010Negativenumberspackwithleadingones-18=11101110-18=1111111111101110Extensionruleofcomplement:leftpacksignbitProofForabinarynumber:A,an-1an-2….a1a0

IfAispositive,an-1=0,then:IfAisnegative,an-1=1,then:9.3IntegerArithmeticNegationSign-magnitude:invertthesignbitComplement:bitwisenot+1E.g.18=0001001011101101+111101110-18=1110111000010001+100010010An-bitbinary:[-2n-1,2n-1-1]proofAddition&SubtractionCommentonAdditionandSubtractionNormalbinaryadditionMonitorsignbitforoverflowOverflowRule:iftwopositivenumbersortwonegativenumbersareadded,iffthesignofresultbecomesinversion,overflowoccurs.

SubtractionRule:Takecomplementofsubtrahendandaddtominuendi.e.a-b=a+(-b)NosubtractorinacomputerSoweonlyneedadditionandcomplementcircuitsHardwareforAdditionandSubtractionMultiplicationUnsignedintegersbyPencil-and-paper1011Multiplicand(11dec)x1101Multiplier(13dec) 1011Partialproducts0000Note:ifmultiplierbitis1copy1011 multiplicand(placevalue)1011 otherwisezero10001111Product(143dec)Note:needdoublelengthresultBycomputerMoreefficientAdditiononpartialproductratherthanwaitinguntiltheendNoneedforstorageallthepartialproducts,fewerregistersareneededSavesometimeForeach1onthemultiplier,anadditionandashiftoperationarerequired,butforeach0,onlyashiftisrequiredBlockDiagramofMultiplierSpecification3n-bitregisters:Q,M,A;one1-bitregister:C;initiallysetA,Cto0ControllogicreadsthebitsofthemultiplieroneatatimeIfQ0=1,thenthemultiplicandisaddedtotheAandtheresultsisstoredintheAThen,allofthebitsofC,AandQareshiftedrightonebit,Q0islostIfQ0=0,justrightshiftTheresulting2n-bitproductisintheAandQExecutionofExampleFlowchartforUnsignedBinaryMultiplicationMultiplyingNegativeNumbersStraightforwardmultiplicationdoesnotwork!1001(-7)x0011(3)1001100111011(27)(-5)XSolution1ConverttopositiveifrequiredMultiplyasaboveIfsignsweredifferent,negateanswerSolution2Booth’salgorithmBooth’sAlgorithmExampleofBooth’sAlgorithmExampleofBooth’sAlgorithm0000001101001InitialValues0011100111001ShiftRight0001110011001ShiftRight

1010110011001A=A+M1101011001001ShiftRight

0111001101001A=A-M

AQQ-1M1110101101001ShiftRight

ExampleofBooth’sAlgorithm(3)DivisionMorecomplexthanmultiplicationNegativenumbersarereallybad!BasedonlongdivisionDivisionofUnsignedBinaryIntegersFlowchartforUnsignedBinaryDivisionNegativeNumbersDivisionThemethodgiveninourbookistootroublesomeAsimpleschemeConverttopositiveifrequireddivisionasaboveIfsignsweredifferent,negateanswerSignIntegerdivision9.4FloatingPointRepresentationRealNumbersNumberswithfractionsCouldbedoneinpurebinary1001.1010=24+20+2-1+2-3=9.625Whereisthebinarypoint?Fixed?VerylimitedMoving?Howdoyoushowwhereitis?Principles±SB±E±:SignS:significandE:exponent,incomputer,usuallybiasedrepresentation±SBE‘B:baseisimplicit,neednotbestoredTypically,thebias=2k-1-1k:numberofbitsofexponentE.g.8-bitfield,thebiasis127Trueexponentvalues:[-127,128]Exponentvalue=trueexponent+biasThus,storedexponentvalueisunsignedTypical32-bitFloat-pointFormatSignsforExponentExponentisinexcessorbiasednotatione.g.Excess(bias)127means8bitexponentfieldPurevaluerange0-255Subtract127togetcorrectvalueRange-127to+128NormalizationFPnumbersareusuallynormalizedi.e.exponentisadjustedsothatleadingbit(MSB)ofmantissais1Sinceitisalways1thereisnoneedtostoreitc.f.Scientificnotationwherenumbersarenormalizedtogiveasingledigitbeforethedecimalpointe.g.3.123x103FPRangesFPRangesFora32bitnumber8bitexponent+/-21283.4x1038AccuracyTheeffectofchanginglsbofmantissa23bitmantissa2-231.2x10-7About6decimalplacesRelation:whenbitsofEareincreased,weexpandtherangeofexpressibledata,butresultinreductionofprecision(Elarger,mantissasmaller,scopelarger,precisionsmaller)Trade-offbetweenrangeandprecision

DensityofFloatingPointNumbers9.5Floating-pointarithmeticForadditionandsubtraction,wemustensurethatbothoperandshavethesameexponentvalue,whilemultiplicationanddivisionaremoresimple.X=XSBXe,Y=YSBYeX+Y=(XSBXe-Ye+YS)

BYeX-Y=(XSBXe-Ye-YS)

BYeXY=(XSYS)

BXe+Ye

X/Y=(XSYS)

BXe-YeFloating-pointoperationmaycausesomeproblems:ExponentoverflowExponentunderflowSignificantunderflowSignificantoverflowFPArithmetic+/-CheckforzerosAlignsignificands(adjustingexponents)ShiftingtheradixpointonthesmalleroperandOncetheoverflowoccurs,theinfluenceissmaller

AddorsubtractsignificandsNormalizeresultFPAdd&SubFPArit

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论