ComputerSystems:AProgrammersPerspective

Study Guides Aug 4, 2025
Loading...

Loading document viewer...

Page 0 of 0

Document Text

2 1 / 4

ComputerSystems:AProgrammer'sPerspective

Instructor'sSolutionManual 1 RandalE.Bryant DavidR.O'Hallaron December4,2003 1 Copyrightc

2003,R.E.Bryant,D.R.O'Hallaron.Allrightsreserved. 2 / 4

Chapter1 SolutionstoHomeworkProblems

Thetextusestwodifferentkindsofexercises:

PracticeProblems.Theseareproblemsthatareincorporateddirectlyintothetext,withexplanatory solutionsattheendofeachchapter.Ourintentionisthatstudentswillworkontheseproblemsasthey readthebook.Eachonehighlightssomeparticularconcept.

HomeworkProblems.Thesearefoundattheendofeachchapter.Theyvaryincomplexityfrom simpledrillstomulti-weeklabsandaredesignedforinstructorstogiveasassignmentsortouseas recitationexamples.Thisdocumentgivesthesolutionstothehomeworkproblems.

1.1Chapter1:ATourofComputerSystems

1.2Chapter2:RepresentingandManipulatingInformation

Problem2.40Solution:

Thisexerciseshouldbeastraightforwardvariationontheexistingcode.code/data/show-ans.c 1voidshow_short(short intx) 2{

  • show_bytes((byte_pointer) &x,sizeof(shortint));
  • 4} 5 6voidshow_long(longintx) 7{

  • show_bytes((byte_pointer) &x,sizeof(long));
  • 9}

1 3 / 4

2CHAPTER1.SOLUTIONSTOHOMEWORKPROBLEMS

10 11voidshow_double(double x) 12{ 13 show_bytes((byte_pointer) &x,sizeof(double)); 14} code/data/show-ans.c

Problem2.41Solution:

Therearemanywaystosolvethisproblem.Thebasicideaistocreatesomemultibytedatumwithdifferent valuesforthemostandleast-signicantbytes.Wethenreadbyte0anddeterminewhichbyteitis.Inthefollowingsolutionistocreateanintwithvalue1.Wethenaccessitsrstbyteandconvertittoan int.Thisbytewillequal0onabig-endianmachineand1onalittle-endianmachine.code/data/show-ans.c 1intis_little_endian(void) 2{

3 /*MSB=0,LSB=1*/

  • intx=1;
  • 5

  • /*ReturnMSBwhenbig-endian,LSBwhenlittle-endian*/
  • return(int)(*(char*)&x);
  • 8} code/data/show-ans.c

Problem2.42Solution:

Thisisasimpleexerciseinmaskingandbitmanipulation.Itisimportanttomentionthat˜0xFFisaway togenerateamaskthatselectsallbuttheleastsignicantbytethatworksforanywordsize.(x&0xFF)|(y&˜0xFF)

Problem2.43Solution:

Theseexercisesrequirethinkingaboutthelogicaloperation!inanontraditionalway.Normallywethink ofitaslogicalnegation.Moregenerally,itdetectswhetherthereisanynonzerobitinaword.A.!!x B.!!˜x C.!!(x&0xFF) D.!!(˜x&0xFF)

Problem2.44Solution:

  • / 4

Download Document

Buy This Document

$30.00 One-time purchase
Buy Now
  • Full access to this document
  • Download anytime
  • No expiration

Document Information

Category: Study Guides
Added: Aug 4, 2025
Description:

ComputerSystems:AProgrammer'sPerspective Instructor'sSolutionManual RandalE.Bryant DavidR.O'Hallaron December4,2003 Copyrightc 2003,R.E.Bryant,D.R.O'Hallaron.Allrightsreserved. Chapter1 Solutionsto...

Get this document $30.00