第一范文网 - 专业文章范例文档资料分享平台

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

来源:用户分享 时间:2025/6/13 10:20:41 本文由闂佸搫顦壕顓㈠礉閿燂拷 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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.

深入理解计算机系统答案 超高清电子版.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c0or6w12a7c5o77k30e8m0fvqu4yw9b00pbi_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top