Contents
Preface xix About the Authors xxxv
1
A Tour of Computer Systems 1
1.1Information Is Bits + Context 3
1.2Programs Are Translated by Other Programs into Different Forms 4
1.3It Pays to Understand How Compilation Systems Work 6
1.4Processors Read and Interpret Instructions Stored in Memory 7
1.4.1Hardware Organization of a System 8
1.4.2Running the helloProgram 10
1.5Caches Matter 11
1.6Storage Devices Form a Hierarchy 14
1.7The Operating System Manages the Hardware 14
1.7.1Processes 15
1.7.2Threads 17
1.7.3Virtual Memory 18
1.7.4Files 19
1.8Systems Communicate with Other Systems Using Networks 19
1.9Important Themes 22
1.9.1Amdahl’s Law 22
1.9.2Concurrency and Parallelism 24
1.9.3The Importance of Abstractions in Computer Systems 26
1.10Summary 27 Bibliographic Notes 28 Solutions to Practice Problems 28
Part I Program Structure and Execution
2
Representing and Manipulating Information 31
2.1Information Storage 34
2.1.1Hexadecimal Notation 36
2.1.2Data Sizes 39
2.1.3 Addressing and Byte Ordering 42
2.1.4 Representing Strings 49
2.1.5 Representing Code 49
2.1.6 Introduction to Boolean Algebra 50
2.1.7 Bit-Level Operations in C 54
2.1.8 Logical Operations in C 56
2.1.9 Shift Operations in C 57
2.2 Integer Representations 59
2.2.1 Integral Data Types 60
2.2.2 Unsigned Encodings 62
2.2.3 Two’s-Complement Encodings 64
2.2.4 Conversions between Signed and Unsigned 70
2.2.5 Signed versus Unsigned in C 74
2.2.6 Expanding the Bit Representation of a Number 76
2.2.7 Truncating Numbers 81
2.2.8 Advice on Signed versus Unsigned 83
2.3 Integer Arithmetic 84
2.3.1 Unsigned Addition 84
2.3.2 Two’s-Complement Addition 90
2.3.3 Two’s-Complement Negation 95
2.3.4 Unsigned Multiplication 96
2.3.5 Two’s-Complement Multiplication 97
2.3.6 Multiplying by Constants 101
2.3.7 Dividing by Powers of 2 103
2.3.8 Final Thoughts on Integer Arithmetic 107
2.4 Floating Point 108
2.4.1 Fractional Binary Numbers 109
2.4.2 IEEE Floating-Point Representation 112
2.4.3 Example Numbers 115
2.4.4 Rounding 120
2.4.5 Floating-Point Operations 122
2.4.6 Floating Point in C 124
2.5 Summary 126
Bibliographic Notes 127
Homework Problems 128
Solutions to Practice Problems 143
3
Machine-Level Representation of Programs 163
3.1 A Historical Perspective 166
3.2Program Encodings 169
3.2.1Machine-Level Code 170
3.2.2Code Examples 172
3.2.3Notes on Formatting 175
3.3Data Formats 177
3.4Accessing Information 179
3.4.1Operand Speci.ers 180
3.4.2Data Movement Instructions 182
3.4.3Data Movement Example 186
3.4.4Pushing and Popping Stack Data 189
3.5Arithmetic and Logical Operations 191
3.5.1Load Effective Address 191
3.5.2Unary and Binary Operations 194
3.5.3Shift Operations 194
3.5.4Discussion 196
3.5.5Special Arithmetic Operations 197
3.6Control 200
3.6.1Condition Codes 201
3.6.2Accessing the Condition Codes 202
3.6.3Jump Instructions 205
3.6.4Jump Instruction Encodings 207
3.6.5Implementing Conditional Branches withConditional Control 209
3.6.6Implementing Conditional Branches withConditional Moves 214
3.6.7Loops 220
3.6.8Switch Statements 232
3.7Procedures 238
3.7.1The Run-Time Stack 239
3.7.2Control Transfer 241
3.7.3Data Transfer 245
3.7.4Local Storage on the Stack 248
3.7.5Local Storage in Registers 251
3.7.6Recursive Procedures 253
3.8Array Allocation and Access 255
3.8.1Basic Principles 255
3.8.2Pointer Arithmetic 257
3.8.3Nested Arrays 258
3.8.4Fixed-Size Arrays 260
3.8.5Variable-Size Arrays 262
3.9 Heterogeneous Data Structures 265
3.9.1 Structures 265
3.9.2 Unions 269
3.9.3 Data Alignment 273
3.10 Combining Control and Data in Machine-Level Programs 276
3.10.1 Understanding Pointers 277
3.10.2 Life in the Real World: Using the gdbDebugger 279
3.10.3 Out-of-Bounds Memory References and Bu
......