好文档 - 专业文书写作范文服务资料分享网站

深入理解计算机系统答案 超高清电子版

天下 分享 时间: 加入收藏 我要投稿 点赞

ComputerSystems:AProgrammer’sPerspective

Instructor’sSolutionManual1

RandalE.BryantDavidR.O’HallaronDecember4,2003

1

Copyrightc2003,R.E.Bryant,D.R.O’Hallaron.Allrightsreserved.

2

Chapter1

SolutionstoHomeworkProblems

Thetextusestwodifferentkindsofexercises:

PracticeProblems.Theseareproblemsthatareincorporateddirectlyintothetext,withexplanatorysolutionsattheendofeachchapter.Ourintentionisthatstudentswillworkontheseproblemsastheyreadthebook.Eachonehighlightssomeparticularconcept.

HomeworkProblems.Thesearefoundattheendofeachchapter.Theyvaryincomplexityfromsimpledrillstomulti-weeklabsandaredesignedforinstructorstogiveasassignmentsortouseasrecitationexamples.

Thisdocumentgivesthesolutionstothehomeworkproblems.

1.1Chapter1:ATourofComputerSystems

1.2Chapter2:RepresentingandManipulatingInformation

Problem2.40Solution:

Thisexerciseshouldbeastraightforwardvariationontheexistingcode.

2

1011121314

CHAPTER1.SOLUTIONSTOHOMEWORKPROBLEMSvoidshow_double(doublex){

show_bytes((byte_pointer)&x,sizeof(double));}

code/data/show-ans.c

12345678

intis_little_endian(void){

/*MSB=0,LSB=1*/intx=1;

/*ReturnMSBwhenbig-endian,LSBwhenlittle-endian*/return(int)(*(char*)&x);}

1.2.CHAPTER2:REPRESENTINGANDMANIPULATINGINFORMATION3

Therearemanysolutionstothisproblem,butitisalittlebittrickytowriteonethatworksforanywordsize.Hereisoursolution:

code/data/shift-ans.c

Theabovecodepeformsarightshiftofawordinwhichallbitsaresetto1.Iftheshiftisarithmetic,theresultingwordwillstillhaveallbitssetto1.Problem2.45Solution:

Thisproblemillustratessomeofthechallengesofwritingportablecode.Thefactthat1<<32yields0onsome32-bitmachinesand1onothersiscommonsourceofbugs.

A.TheCstandarddoesnotde?netheeffectofashiftby32ofa32-bitdatum.OntheSPARC(andmanyothermachines),theexpressionx<

B.Computebeyond_msbas2<<31.

C.Wecannotshiftbymorethan15bitsatatime,butwecancomposemultipleshiftstogetthedesiredeffect.Thus,wecancomputeset_msbas2<<15<<15,andbeyond_msbasset_msb<<1.Problem2.46Solution:

Thisproblemhighlightsthedifferencebetweenzeroextensionandsignextension.Italsoprovidesanexcusetoshowaninterestingtrickthatcompilersoftenusetouseshiftingtoperformmaskingandsignextension.A.Thefunctiondoesnotperformanysignextension.Forexample,ifweattempttoextractbyte0fromword0xFF,wewillget255,ratherthan.

B.Thefollowingcodeusesawell-knowntrickforusingshiftstoisolateaparticularrangeofbitsandtoperformsignextensionatthesametime.First,weperformaleftshiftsothatthemostsigni?cantbitofthedesiredbyteisatbitposition31.Thenwerightshiftby24,movingthebyteintotheproperpositionandpeformingsignextensionatthesametime.

深入理解计算机系统答案 超高清电子版

ComputerSystems:AProgrammer’sPerspectiveInstructor’sSolutionManual1RandalE.BryantDavidR.O’HallaronDecember4,20031Copyrightc2003,R.E.Bryant,D.R.O’Hallaron.Allrightsreserv
推荐度:
点击下载文档文档为doc格式
0or6w12a7c5o77k30e8m0fvqu4yw9b00pbi
领取福利

微信扫码领取福利

微信扫码分享