ebook img

Computer Systems: A Programmer's Perspective PDF

1078 Pages·2011·6.492 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Computer Systems: A Programmer's Perspective

Computer Systems A Programmer’s Perspective This page intentionally left blank Computer Systems A Programmer’s Perspective Randal E. Bryant Carnegie Mellon University David R. O’Hallaron Carnegie Mellon University and Intel Labs PrenticeHall Boston Columbus Indianapolis NewYork SanFrancisco UpperSaddleRiver Amsterdam CapeTown Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi MexicoCity SaoPaulo Sydney HongKong Seoul Singapore Taipei Tokyo EditorialDirector:MarciaHorton Editor-in-Chief:MichaelHirsch AcquisitionsEditor:MattGoldstein EditorialAssistant:ChelseaBell DirectorofMarketing:MargaretWaples MarketingCoordinator:KathrynFerranti ManagingEditor:JeffHolcomb SeniorManufacturingBuyer:CarolMelville ArtDirector:LindaKnowles CoverDesigner:ElenaSidorova ImageInteriorPermissionCoordinator:RichardRodrigues CoverArt:©RandalE.BryantandDavidR.O’Hallaron MediaProducer:KatelynBoller ProjectManagementandInteriorDesign:PaulC.Anagnostopoulos,WindfallSoftware Composition:JoeSnowden,CoventryComposition Printer/Binder:EdwardsBrothers CoverPrinter:Lehigh-PhoenixColor/Hagerstown Copyright©2011,2003byRandalE.BryantandDavidR.O’Hallaron.Allrightsreserved. ManufacturedintheUnitedStatesofAmerica.ThispublicationisprotectedbyCopyright, andpermissionshouldbeobtainedfromthepublisherpriortoanyprohibitedreproduction, storageinaretrievalsystem, ortransmissioninanyformorbyanymeans, electronic, mechanical,photocopying,recording,orlikewise.Toobtainpermission(s)tousematerial fromthiswork,pleasesubmitawrittenrequesttoPearsonEducation,Inc.,Permissions Department,501BoylstonStreet,Suite900,Boston,Massachusetts02116. Manyofthedesignationsbymanufacturersandsellertodistinguishtheirproductsare claimedastrademarks.Wherethosedesignationsappearinthisbook,andthepublisher wasawareofatrademarkclaim,thedesignationshavebeenprintedininitialcapsorall caps. LibraryofCongressCataloging-in-PublicationData Bryant,Randal. Computersystems:aprogrammer’sperspective/RandalE.Bryant,DavidR. O’Hallaron.—2nded. p. cm. Includesbibliographicalreferencesandindex. ISBN-13:978-0-13-610804-7(alk.paper) ISBN-10:0-13-610804-0(alk.paper) 1.Computersystems. 2.Computers. 3.Telecommunication. 4.Userinterfaces (Computersystems) I.O’Hallaron,DavidRichard. II.Title. QA76.5.B7952010 004—dc22 2009053083 10 9 8 7 6 5 4 3 2 1—EB—14 13 12 11 10 ISBN10:0-13-610804-0 ISBN13:978-0-13-610804-7 To the students and instructors of the 15-213 course at Carnegie Mellon University, for inspiring us to develop and refine the material for this book. This page intentionally left blank Contents Preface xix AbouttheAuthors xxxiii 1 A Tour of Computer Systems 1 1.1 InformationIsBits+Context 3 1.2 ProgramsAreTranslatedbyOtherProgramsintoDifferentForms 4 1.3 ItPaystoUnderstandHowCompilationSystemsWork 6 1.4 ProcessorsReadandInterpretInstructionsStoredinMemory 7 1.4.1 HardwareOrganizationofaSystem 7 1.4.2 RunningthehelloProgram 10 1.5 CachesMatter 12 1.6 StorageDevicesFormaHierarchy 13 1.7 TheOperatingSystemManagestheHardware 14 1.7.1 Processes 16 1.7.2 Threads 17 1.7.3 VirtualMemory 17 1.7.4 Files 19 1.8 SystemsCommunicatewithOtherSystemsUsingNetworks 20 1.9 ImportantThemes 21 1.9.1 ConcurrencyandParallelism 21 1.9.2 TheImportanceofAbstractionsinComputerSystems 24 1.10 Summary 25 BibliographicNotes 26 Part I Program Structure and Execution 2 Representing and Manipulating Information 29 2.1 InformationStorage 33 2.1.1 HexadecimalNotation 34 2.1.2 Words 38 2.1.3 DataSizes 38 vii viii Contents 2.1.4 AddressingandByteOrdering 39 2.1.5 RepresentingStrings 46 2.1.6 RepresentingCode 47 2.1.7 IntroductiontoBooleanAlgebra 48 2.1.8 Bit-LevelOperationsinC 51 2.1.9 LogicalOperationsinC 54 2.1.10 ShiftOperationsinC 54 2.2 IntegerRepresentations 56 2.2.1 IntegralDataTypes 57 2.2.2 UnsignedEncodings 58 2.2.3 Two’s-ComplementEncodings 60 2.2.4 ConversionsBetweenSignedandUnsigned 65 2.2.5 Signedvs.UnsignedinC 69 2.2.6 ExpandingtheBitRepresentationofaNumber 71 2.2.7 TruncatingNumbers 75 2.2.8 AdviceonSignedvs.Unsigned 76 2.3 IntegerArithmetic 79 2.3.1 UnsignedAddition 79 2.3.2 Two’s-ComplementAddition 83 2.3.3 Two’s-ComplementNegation 87 2.3.4 UnsignedMultiplication 88 2.3.5 Two’s-ComplementMultiplication 89 2.3.6 MultiplyingbyConstants 92 2.3.7 DividingbyPowersofTwo 95 2.3.8 FinalThoughtsonIntegerArithmetic 98 2.4 FloatingPoint 99 2.4.1 FractionalBinaryNumbers 100 2.4.2 IEEEFloating-PointRepresentation 103 2.4.3 ExampleNumbers 105 2.4.4 Rounding 110 2.4.5 Floating-PointOperations 113 2.4.6 FloatingPointinC 114 2.5 Summary 118 BibliographicNotes 119 HomeworkProblems 119 SolutionstoPracticeProblems 134 3 Machine-Level Representation of Programs 153 3.1 AHistoricalPerspective 156 3.2 ProgramEncodings 159 Contents ix 3.2.1 Machine-LevelCode 160 3.2.2 CodeExamples 162 3.2.3 NotesonFormatting 165 3.3 DataFormats 167 3.4 AccessingInformation 168 3.4.1 OperandSpecifiers 169 3.4.2 DataMovementInstructions 171 3.4.3 DataMovementExample 174 3.5 ArithmeticandLogicalOperations 177 3.5.1 LoadEffectiveAddress 177 3.5.2 UnaryandBinaryOperations 178 3.5.3 ShiftOperations 179 3.5.4 Discussion 180 3.5.5 SpecialArithmeticOperations 182 3.6 Control 185 3.6.1 ConditionCodes 185 3.6.2 AccessingtheConditionCodes 187 3.6.3 JumpInstructionsandTheirEncodings 189 3.6.4 TranslatingConditionalBranches 193 3.6.5 Loops 197 3.6.6 ConditionalMoveInstructions 206 3.6.7 SwitchStatements 213 3.7 Procedures 219 3.7.1 StackFrameStructure 219 3.7.2 TransferringControl 221 3.7.3 RegisterUsageConventions 223 3.7.4 ProcedureExample 224 3.7.5 RecursiveProcedures 229 3.8 ArrayAllocationandAccess 232 3.8.1 BasicPrinciples 232 3.8.2 PointerArithmetic 233 3.8.3 NestedArrays 235 3.8.4 Fixed-SizeArrays 237 3.8.5 Variable-SizeArrays 238 3.9 HeterogeneousDataStructures 241 3.9.1 Structures 241 3.9.2 Unions 244 3.9.3 DataAlignment 248 3.10 PuttingItTogether:UnderstandingPointers 252 3.11 LifeintheRealWorld:UsingthegdbDebugger 254 3.12 Out-of-BoundsMemoryReferencesandBufferOverflow 256 3.12.1 ThwartingBufferOverflowAttacks 261

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.