100% found this document useful (7 votes)
97 views

(eBook PDF) Computer Systems: A Programmer's Perspective 3nd Editionpdf download

The document provides information about various eBooks available for download, including titles related to computer systems and health informatics. It highlights the third edition of 'Computer Systems: A Programmer's Perspective' and other related texts, emphasizing their educational value. Links to download these eBooks are included, along with a brief description of the global editions tailored for international students.

Uploaded by

baazpambu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (7 votes)
97 views

(eBook PDF) Computer Systems: A Programmer's Perspective 3nd Editionpdf download

The document provides information about various eBooks available for download, including titles related to computer systems and health informatics. It highlights the third edition of 'Computer Systems: A Programmer's Perspective' and other related texts, emphasizing their educational value. Links to download these eBooks are included, along with a brief description of the global editions tailored for international students.

Uploaded by

baazpambu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

(eBook PDF) Computer Systems: A Programmer's

Perspective 3nd Edition instant download

https://ebooksecure.com/product/ebook-pdf-computer-systems-a-
programmers-perspective-3nd-edition/

Download more ebook from https://ebooksecure.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebooksecure.com
to discover even more!

(eBook PDF) Health Informatics: A Systems Perspective,


Second Edition

http://ebooksecure.com/product/ebook-pdf-health-informatics-a-
systems-perspective-second-edition/

(eBook PDF) Health Informatics: A Systems Perspective


First Edition

http://ebooksecure.com/product/ebook-pdf-health-informatics-a-
systems-perspective-first-edition/

(eBook PDF) Comparative Health Systems: A Global


Perspective 2nd Edition

http://ebooksecure.com/product/ebook-pdf-comparative-health-
systems-a-global-perspective-2nd-edition/

CMOS VLSI Design A Circuits and Systems Perspective


(4th Edition)

http://ebooksecure.com/product/cmos-vlsi-design-a-circuits-and-
systems-perspective-4th-edition/
(eBook PDF) Computer Systems 5th Edition

http://ebooksecure.com/product/ebook-pdf-computer-systems-5th-
edition/

Computer Systems 5th Edition (eBook PDF)

http://ebooksecure.com/product/computer-systems-5th-edition-
ebook-pdf/

(eBook PDF) Health Care Operations Management: A


Systems Perspective 2nd Edition

http://ebooksecure.com/product/ebook-pdf-health-care-operations-
management-a-systems-perspective-2nd-edition/

A New Ecology: Systems Perspective 2nd Edition Soeren


Nors Nielsen - eBook PDF

https://ebooksecure.com/download/a-new-ecology-systems-
perspective-ebook-pdf/

Cardiology-An Integrated Approach (Human Organ Systems)


(Dec 29, 2017)_(007179154X)_(McGraw-Hill) 1st Edition
Elmoselhi - eBook PDF

https://ebooksecure.com/download/cardiology-an-integrated-
approach-human-organ-systems-dec-29-2017_007179154x_mcgraw-hill-
ebook-pdf/
Global Global
edition edition

edition
Global Computer Systems
A Programmer’s Perspective
For these Global Editions, the editorial team at Pearson has
collaborated with educators across the world to address a
wide range of subjects and requirements, equipping students
with the best possible learning tools. This Global Edition
preserves the cutting-edge approach and pedagogy of the
original, but also features alterations, customization, and
adaptation from the North American version.

edition
Third
Computer Systems

Bryant • O’Hallaron
This is a special edition of an established A Programmer’s Perspective
title widely used by colleges and universities
throughout the world. Pearson published this Third edition
exclusive edition for the benefit of students
outside the United States and Canada. If you
purchased this book within the United States
Randal E. Bryant • David R. O’Hallaron
or Canada, you should be aware that it has
been imported without the approval of the
Publisher or Author.

Pearson Global Edition

Bryant_1292101768_mech.indd 1 07/05/15 3:22 PM


Contents

Preface 19
About the Authors 35

1
A Tour of Computer Systems 37
1.1 Information Is Bits + Context 39
1.2 Programs Are Translated by Other Programs into Different Forms 40
1.3 It Pays to Understand How Compilation Systems Work 42
1.4 Processors Read and Interpret Instructions Stored in Memory 43
1.4.1 Hardware Organization of a System 44
1.4.2 Running the hello Program 46
1.5 Caches Matter 47
1.6 Storage Devices Form a Hierarchy 50
1.7 The Operating System Manages the Hardware 50
1.7.1 Processes 51
1.7.2 Threads 53
1.7.3 Virtual Memory 54
1.7.4 Files 55
1.8 Systems Communicate with Other Systems Using Networks 55
1.9 Important Themes 58
1.9.1 Amdahl’s Law 58
1.9.2 Concurrency and Parallelism 60
1.9.3 The Importance of Abstractions in Computer Systems 62
1.10 Summary 63
Bibliographic Notes 64
Solutions to Practice Problems 64

Part I Program Structure and Execution

2
Representing and Manipulating Information 67
2.1 Information Storage 70
2.1.1 Hexadecimal Notation 72
2.1.2 Data Sizes 75
7
8 Contents

2.1.3 Addressing and Byte Ordering 78


2.1.4 Representing Strings 85
2.1.5 Representing Code 85
2.1.6 Introduction to Boolean Algebra 86
2.1.7 Bit-Level Operations in C 90
2.1.8 Logical Operations in C 92
2.1.9 Shift Operations in C 93
2.2 Integer Representations 95
2.2.1 Integral Data Types 96
2.2.2 Unsigned Encodings 98
2.2.3 Two’s-Complement Encodings 100
2.2.4 Conversions between Signed and Unsigned 106
2.2.5 Signed versus Unsigned in C 110
2.2.6 Expanding the Bit Representation of a Number 112
2.2.7 Truncating Numbers 117
2.2.8 Advice on Signed versus Unsigned 119
2.3 Integer Arithmetic 120
2.3.1 Unsigned Addition 120
2.3.2 Two’s-Complement Addition 126
2.3.3 Two’s-Complement Negation 131
2.3.4 Unsigned Multiplication 132
2.3.5 Two’s-Complement Multiplication 133
2.3.6 Multiplying by Constants 137
2.3.7 Dividing by Powers of 2 139
2.3.8 Final Thoughts on Integer Arithmetic 143
2.4 Floating Point 144
2.4.1 Fractional Binary Numbers 145
2.4.2 IEEE Floating-Point Representation 148
2.4.3 Example Numbers 151
2.4.4 Rounding 156
2.4.5 Floating-Point Operations 158
2.4.6 Floating Point in C 160
2.5 Summary 162
Bibliographic Notes 163
Homework Problems 164
Solutions to Practice Problems 179

3
Machine-Level Representation of Programs 199
3.1 A Historical Perspective 202
Contents 9

3.2 Program Encodings 205


3.2.1 Machine-Level Code 206
3.2.2 Code Examples 208
3.2.3 Notes on Formatting 211
3.3 Data Formats 213
3.4 Accessing Information 215
3.4.1 Operand Specifiers 216
3.4.2 Data Movement Instructions 218
3.4.3 Data Movement Example 222
3.4.4 Pushing and Popping Stack Data 225
3.5 Arithmetic and Logical Operations 227
3.5.1 Load Effective Address 227
3.5.2 Unary and Binary Operations 230
3.5.3 Shift Operations 230
3.5.4 Discussion 232
3.5.5 Special Arithmetic Operations 233
3.6 Control 236
3.6.1 Condition Codes 237
3.6.2 Accessing the Condition Codes 238
3.6.3 Jump Instructions 241
3.6.4 Jump Instruction Encodings 243
3.6.5 Implementing Conditional Branches with
Conditional Control 245
3.6.6 Implementing Conditional Branches with
Conditional Moves 250
3.6.7 Loops 256
3.6.8 Switch Statements 268
3.7 Procedures 274
3.7.1 The Run-Time Stack 275
3.7.2 Control Transfer 277
3.7.3 Data Transfer 281
3.7.4 Local Storage on the Stack 284
3.7.5 Local Storage in Registers 287
3.7.6 Recursive Procedures 289
3.8 Array Allocation and Access 291
3.8.1 Basic Principles 291
3.8.2 Pointer Arithmetic 293
3.8.3 Nested Arrays 294
3.8.4 Fixed-Size Arrays 296
3.8.5 Variable-Size Arrays 298
10 Contents

3.9 Heterogeneous Data Structures 301


3.9.1 Structures 301
3.9.2 Unions 305
3.9.3 Data Alignment 309
3.10 Combining Control and Data in Machine-Level Programs 312
3.10.1 Understanding Pointers 313
3.10.2 Life in the Real World: Using the gdb Debugger 315
3.10.3 Out-of-Bounds Memory References and Buffer Overflow 315
3.10.4 Thwarting Buffer Overflow Attacks 320
3.10.5 Supporting Variable-Size Stack Frames 326
3.11 Floating-Point Code 329
3.11.1 Floating-Point Movement and Conversion Operations 332
3.11.2 Floating-Point Code in Procedures 337
3.11.3 Floating-Point Arithmetic Operations 338
3.11.4 Defining and Using Floating-Point Constants 340
3.11.5 Using Bitwise Operations in Floating-Point Code 341
3.11.6 Floating-Point Comparison Operations 342
3.11.7 Observations about Floating-Point Code 345
3.12 Summary 345
Bibliographic Notes 346
Homework Problems 347
Solutions to Practice Problems 361

4
Processor Architecture 387
4.1 The Y86-64 Instruction Set Architecture 391
4.1.1 Programmer-Visible State 391
4.1.2 Y86-64 Instructions 392
4.1.3 Instruction Encoding 394
4.1.4 Y86-64 Exceptions 399
4.1.5 Y86-64 Programs 400
4.1.6 Some Y86-64 Instruction Details 406
4.2 Logic Design and the Hardware Control Language HCL 408
4.2.1 Logic Gates 409
4.2.2 Combinational Circuits and HCL Boolean Expressions 410
4.2.3 Word-Level Combinational Circuits and HCL
Integer Expressions 412
4.2.4 Set Membership 416
4.2.5 Memory and Clocking 417
4.3 Sequential Y86-64 Implementations 420
4.3.1 Organizing Processing into Stages 420
Contents 11

4.3.2 SEQ Hardware Structure 432


4.3.3 SEQ Timing 436
4.3.4 SEQ Stage Implementations 440
4.4 General Principles of Pipelining 448
4.4.1 Computational Pipelines 448
4.4.2 A Detailed Look at Pipeline Operation 450
4.4.3 Limitations of Pipelining 452
4.4.4 Pipelining a System with Feedback 455
4.5 Pipelined Y86-64 Implementations 457
4.5.1 SEQ+: Rearranging the Computation Stages 457
4.5.2 Inserting Pipeline Registers 458
4.5.3 Rearranging and Relabeling Signals 462
4.5.4 Next PC Prediction 463
4.5.5 Pipeline Hazards 465
4.5.6 Exception Handling 480
4.5.7 PIPE Stage Implementations 483
4.5.8 Pipeline Control Logic 491
4.5.9 Performance Analysis 500
4.5.10 Unfinished Business 504
4.6 Summary 506
4.6.1 Y86-64 Simulators 508
Bibliographic Notes 509
Homework Problems 509
Solutions to Practice Problems 516

5
Optimizing Program Performance 531
5.1 Capabilities and Limitations of Optimizing Compilers 534
5.2 Expressing Program Performance 538
5.3 Program Example 540
5.4 Eliminating Loop Inefficiencies 544
5.5 Reducing Procedure Calls 548
5.6 Eliminating Unneeded Memory References 550
5.7 Understanding Modern Processors 553
5.7.1 Overall Operation 554
5.7.2 Functional Unit Performance 559
5.7.3 An Abstract Model of Processor Operation 561
5.8 Loop Unrolling 567
5.9 Enhancing Parallelism 572
5.9.1 Multiple Accumulators 572
5.9.2 Reassociation Transformation 577
12 Contents

5.10 Summary of Results for Optimizing Combining Code 583


5.11 Some Limiting Factors 584
5.11.1 Register Spilling 584
5.11.2 Branch Prediction and Misprediction Penalties 585
5.12 Understanding Memory Performance 589
5.12.1 Load Performance 590
5.12.2 Store Performance 591
5.13 Life in the Real World: Performance Improvement Techniques 597
5.14 Identifying and Eliminating Performance Bottlenecks 598
5.14.1 Program Profiling 598
5.14.2 Using a Profiler to Guide Optimization 601
5.15 Summary 604
Bibliographic Notes 605
Homework Problems 606
Solutions to Practice Problems 609

6
The Memory Hierarchy 615
6.1 Storage Technologies 617
6.1.1 Random Access Memory 617
6.1.2 Disk Storage 625
6.1.3 Solid State Disks 636
6.1.4 Storage Technology Trends 638
6.2 Locality 640
6.2.1 Locality of References to Program Data 642
6.2.2 Locality of Instruction Fetches 643
6.2.3 Summary of Locality 644
6.3 The Memory Hierarchy 645
6.3.1 Caching in the Memory Hierarchy 646
6.3.2 Summary of Memory Hierarchy Concepts 650
6.4 Cache Memories 650
6.4.1 Generic Cache Memory Organization 651
6.4.2 Direct-Mapped Caches 653
6.4.3 Set Associative Caches 660
6.4.4 Fully Associative Caches 662
6.4.5 Issues with Writes 666
6.4.6 Anatomy of a Real Cache Hierarchy 667
6.4.7 Performance Impact of Cache Parameters 667
6.5 Writing Cache-Friendly Code 669
6.6 Putting It Together: The Impact of Caches on Program Performance 675
Contents 13

6.6.1 The Memory Mountain 675


6.6.2 Rearranging Loops to Increase Spatial Locality 679
6.6.3 Exploiting Locality in Your Programs 683
6.7 Summary 684
Bibliographic Notes 684
Homework Problems 685
Solutions to Practice Problems 696

Part II Running Programs on a System

7
Linking 705
7.1 Compiler Drivers 707
7.2 Static Linking 708
7.3 Object Files 709
7.4 Relocatable Object Files 710
7.5 Symbols and Symbol Tables 711
7.6 Symbol Resolution 715
7.6.1 How Linkers Resolve Duplicate Symbol Names 716
7.6.2 Linking with Static Libraries 720
7.6.3 How Linkers Use Static Libraries to Resolve References 724
7.7 Relocation 725
7.7.1 Relocation Entries 726
7.7.2 Relocating Symbol References 727
7.8 Executable Object Files 731
7.9 Loading Executable Object Files 733
7.10 Dynamic Linking with Shared Libraries 734
7.11 Loading and Linking Shared Libraries from Applications 737
7.12 Position-Independent Code (PIC) 740
7.13 Library Interpositioning 743
7.13.1 Compile-Time Interpositioning 744
7.13.2 Link-Time Interpositioning 744
7.13.3 Run-Time Interpositioning 746
7.14 Tools for Manipulating Object Files 749
7.15 Summary 749
Bibliographic Notes 750
Homework Problems 750
Solutions to Practice Problems 753
14 Contents

8
Exceptional Control Flow 757
8.1 Exceptions 759
8.1.1 Exception Handling 760
8.1.2 Classes of Exceptions 762
8.1.3 Exceptions in Linux/x86-64 Systems 765
8.2 Processes 768
8.2.1 Logical Control Flow 768
8.2.2 Concurrent Flows 769
8.2.3 Private Address Space 770
8.2.4 User and Kernel Modes 770
8.2.5 Context Switches 772
8.3 System Call Error Handling 773
8.4 Process Control 774
8.4.1 Obtaining Process IDs 775
8.4.2 Creating and Terminating Processes 775
8.4.3 Reaping Child Processes 779
8.4.4 Putting Processes to Sleep 785
8.4.5 Loading and Running Programs 786
8.4.6 Using fork and execve to Run Programs 789
8.5 Signals 792
8.5.1 Signal Terminology 794
8.5.2 Sending Signals 795
8.5.3 Receiving Signals 798
8.5.4 Blocking and Unblocking Signals 800
8.5.5 Writing Signal Handlers 802
8.5.6 Synchronizing Flows to Avoid Nasty Concurrency Bugs 812
8.5.7 Explicitly Waiting for Signals 814
8.6 Nonlocal Jumps 817
8.7 Tools for Manipulating Processes 822
8.8 Summary 823
Bibliographic Notes 823
Homework Problems 824
Solutions to Practice Problems 831

9
Virtual Memory 837
9.1 Physical and Virtual Addressing 839
9.2 Address Spaces 840
Contents 15

9.3 VM as a Tool for Caching 841


9.3.1 DRAM Cache Organization 842
9.3.2 Page Tables 842
9.3.3 Page Hits 844
9.3.4 Page Faults 844
9.3.5 Allocating Pages 846
9.3.6 Locality to the Rescue Again 846
9.4 VM as a Tool for Memory Management 847
9.5 VM as a Tool for Memory Protection 848
9.6 Address Translation 849
9.6.1 Integrating Caches and VM 853
9.6.2 Speeding Up Address Translation with a TLB 853
9.6.3 Multi-Level Page Tables 855
9.6.4 Putting It Together: End-to-End Address Translation 857
9.7 Case Study: The Intel Core i7/Linux Memory System 861
9.7.1 Core i7 Address Translation 862
9.7.2 Linux Virtual Memory System 864
9.8 Memory Mapping 869
9.8.1 Shared Objects Revisited 869
9.8.2 The fork Function Revisited 872
9.8.3 The execve Function Revisited 872
9.8.4 User-Level Memory Mapping with the mmap Function 873
9.9 Dynamic Memory Allocation 875
9.9.1 The malloc and free Functions 876
9.9.2 Why Dynamic Memory Allocation? 879
9.9.3 Allocator Requirements and Goals 880
9.9.4 Fragmentation 882
9.9.5 Implementation Issues 882
9.9.6 Implicit Free Lists 883
9.9.7 Placing Allocated Blocks 885
9.9.8 Splitting Free Blocks 885
9.9.9 Getting Additional Heap Memory 886
9.9.10 Coalescing Free Blocks 886
9.9.11 Coalescing with Boundary Tags 887
9.9.12 Putting It Together: Implementing a Simple Allocator 890
9.9.13 Explicit Free Lists 898
9.9.14 Segregated Free Lists 899
9.10 Garbage Collection 901
9.10.1 Garbage Collector Basics 902
9.10.2 Mark&Sweep Garbage Collectors 903
9.10.3 Conservative Mark&Sweep for C Programs 905
16 Contents

9.11 Common Memory-Related Bugs in C Programs 906


9.11.1 Dereferencing Bad Pointers 906
9.11.2 Reading Uninitialized Memory 907
9.11.3 Allowing Stack Buffer Overflows 907
9.11.4 Assuming That Pointers and the Objects They Point to
Are the Same Size 908
9.11.5 Making Off-by-One Errors 908
9.11.6 Referencing a Pointer Instead of the Object It Points To 909
9.11.7 Misunderstanding Pointer Arithmetic 909
9.11.8 Referencing Nonexistent Variables 910
9.11.9 Referencing Data in Free Heap Blocks 910
9.11.10 Introducing Memory Leaks 911
9.12 Summary 911
Bibliographic Notes 912
Homework Problems 912
Solutions to Practice Problems 916

Part III Interaction and Communication


between Programs

10
System-Level I/O 925
10.1 Unix I/O 926
10.2 Files 927
10.3 Opening and Closing Files 929
10.4 Reading and Writing Files 931
10.5 Robust Reading and Writing with the Rio Package 933
10.5.1 Rio Unbuffered Input and Output Functions 933
10.5.2 Rio Buffered Input Functions 934
10.6 Reading File Metadata 939
10.7 Reading Directory Contents 941
10.8 Sharing Files 942
10.9 I/O Redirection 945
10.10 Standard I/O 947
10.11 Putting It Together: Which I/O Functions Should I Use? 947
10.12 Summary 949
Bibliographic Notes 950
Homework Problems 950
Solutions to Practice Problems 951
Contents 17

11
Network Programming 953
11.1 The Client-Server Programming Model 954
11.2 Networks 955
11.3 The Global IP Internet 960
11.3.1 IP Addresses 961
11.3.2 Internet Domain Names 963
11.3.3 Internet Connections 965
11.4 The Sockets Interface 968
11.4.1 Socket Address Structures 969
11.4.2 The socket Function 970
11.4.3 The connect Function 970
11.4.4 The bind Function 971
11.4.5 The listen Function 971
11.4.6 The accept Function 972
11.4.7 Host and Service Conversion 973
11.4.8 Helper Functions for the Sockets Interface 978
11.4.9 Example Echo Client and Server 980
11.5 Web Servers 984
11.5.1 Web Basics 984
11.5.2 Web Content 985
11.5.3 HTTP Transactions 986
11.5.4 Serving Dynamic Content 989
11.6 Putting It Together: The Tiny Web Server 992
11.7 Summary 1000
Bibliographic Notes 1001
Homework Problems 1001
Solutions to Practice Problems 1002

12
Concurrent Programming 1007
12.1 Concurrent Programming with Processes 1009
12.1.1 A Concurrent Server Based on Processes 1010
12.1.2 Pros and Cons of Processes 1011
12.2 Concurrent Programming with I/O Multiplexing 1013
12.2.1 A Concurrent Event-Driven Server Based on I/O
Multiplexing 1016
12.2.2 Pros and Cons of I/O Multiplexing 1021
12.3 Concurrent Programming with Threads 1021
12.3.1 Thread Execution Model 1022
18 Contents

12.3.2 Posix Threads 1023


12.3.3 Creating Threads 1024
12.3.4 Terminating Threads 1024
12.3.5 Reaping Terminated Threads 1025
12.3.6 Detaching Threads 1025
12.3.7 Initializing Threads 1026
12.3.8 A Concurrent Server Based on Threads 1027
12.4 Shared Variables in Threaded Programs 1028
12.4.1 Threads Memory Model 1029
12.4.2 Mapping Variables to Memory 1030
12.4.3 Shared Variables 1031
12.5 Synchronizing Threads with Semaphores 1031
12.5.1 Progress Graphs 1035
12.5.2 Semaphores 1037
12.5.3 Using Semaphores for Mutual Exclusion 1038
12.5.4 Using Semaphores to Schedule Shared Resources 1040
12.5.5 Putting It Together: A Concurrent Server Based on
Prethreading 1044
12.6 Using Threads for Parallelism 1049
12.7 Other Concurrency Issues 1056
12.7.1 Thread Safety 1056
12.7.2 Reentrancy 1059
12.7.3 Using Existing Library Functions in Threaded Programs 1060
12.7.4 Races 1061
12.7.5 Deadlocks 1063
12.8 Summary 1066
Bibliographic Notes 1066
Homework Problems 1067
Solutions to Practice Problems 1072

A
Error Handling 1077
A.1 Error Handling in Unix Systems 1078
A.2 Error-Handling Wrappers 1079

References 1083

Index 1089
Preface

This book (known as CS:APP) is for computer scientists, computer engineers, and
others who want to be able to write better programs by learning what is going on
“under the hood” of a computer system.
Our aim is to explain the enduring concepts underlying all computer systems,
and to show you the concrete ways that these ideas affect the correctness, perfor-
mance, and utility of your application programs. Many systems books are written
from a builder’s perspective, describing how to implement the hardware or the sys-
tems software, including the operating system, compiler, and network interface.
This book is written from a programmer’s perspective, describing how application
programmers can use their knowledge of a system to write better programs. Of
course, learning what a system is supposed to do provides a good first step in learn-
ing how to build one, so this book also serves as a valuable introduction to those
who go on to implement systems hardware and software. Most systems books also
tend to focus on just one aspect of the system, for example, the hardware archi-
tecture, the operating system, the compiler, or the network. This book spans all
of these aspects, with the unifying theme of a programmer’s perspective.
If you study and learn the concepts in this book, you will be on your way to
becoming the rare power programmer who knows how things work and how to
fix them when they break. You will be able to write programs that make better
use of the capabilities provided by the operating system and systems software,
that operate correctly across a wide range of operating conditions and run-time
parameters, that run faster, and that avoid the flaws that make programs vulner-
able to cyberattack. You will be prepared to delve deeper into advanced topics
such as compilers, computer architecture, operating systems, embedded systems,
networking, and cybersecurity.

Assumptions about the Reader’s Background


This book focuses on systems that execute x86-64 machine code. x86-64 is the latest
in an evolutionary path followed by Intel and its competitors that started with the
8086 microprocessor in 1978. Due to the naming conventions used by Intel for
its microprocessor line, this class of microprocessors is referred to colloquially as
“x86.” As semiconductor technology has evolved to allow more transistors to be
integrated onto a single chip, these processors have progressed greatly in their
computing power and their memory capacity. As part of this progression, they
have gone from operating on 16-bit words, to 32-bit words with the introduction
of IA32 processors, and most recently to 64-bit words with x86-64.
We consider how these machines execute C programs on Linux. Linux is one
of a number of operating systems having their heritage in the Unix operating
system developed originally by Bell Laboratories. Other members of this class

19
20 Preface

New to C? Advice on the C programming language


To help readers whose background in C programming is weak (or nonexistent), we have also included
these special notes to highlight features that are especially important in C. We assume you are familiar
with C++ or Java.

of operating systems include Solaris, FreeBSD, and MacOS X. In recent years,


these operating systems have maintained a high level of compatibility through the
efforts of the Posix and Standard Unix Specification standardization efforts. Thus,
the material in this book applies almost directly to these “Unix-like” operating
systems.
The text contains numerous programming examples that have been compiled
and run on Linux systems. We assume that you have access to such a machine, and
are able to log in and do simple things such as listing files and changing directo-
ries. If your computer runs Microsoft Windows, we recommend that you install
one of the many different virtual machine environments (such as VirtualBox or
VMWare) that allow programs written for one operating system (the guest OS)
to run under another (the host OS).
We also assume that you have some familiarity with C or C++. If your only
prior experience is with Java, the transition will require more effort on your part,
but we will help you. Java and C share similar syntax and control statements.
However, there are aspects of C (particularly pointers, explicit dynamic memory
allocation, and formatted I/O) that do not exist in Java. Fortunately, C is a small
language, and it is clearly and beautifully described in the classic “K&R” text
by Brian Kernighan and Dennis Ritchie [61]. Regardless of your programming
background, consider K&R an essential part of your personal systems library. If
your prior experience is with an interpreted language, such as Python, Ruby, or
Perl, you will definitely want to devote some time to learning C before you attempt
to use this book.
Several of the early chapters in the book explore the interactions between C
programs and their machine-language counterparts. The machine-language exam-
ples were all generated by the GNU gcc compiler running on x86-64 processors.
We do not assume any prior experience with hardware, machine language, or
assembly-language programming.

How to Read the Book


Learning how computer systems work from a programmer’s perspective is great
fun, mainly because you can do it actively. Whenever you learn something new,
you can try it out right away and see the result firsthand. In fact, we believe that
the only way to learn systems is to do systems, either working concrete problems
or writing and running programs on real systems.
This theme pervades the entire book. When a new concept is introduced, it
is followed in the text by one or more practice problems that you should work
Preface 21

code/intro/hello.c
1 #include <stdio.h>
2
3 int main()
4 {
5 printf("hello, world\n");
6 return 0;
7 }
code/intro/hello.c

Figure 1 A typical code example.

immediately to test your understanding. Solutions to the practice problems are


at the end of each chapter. As you read, try to solve each problem on your own
and then check the solution to make sure you are on the right track. Each chapter
is followed by a set of homework problems of varying difficulty. Your instructor
has the solutions to the homework problems in an instructor’s manual. For each
homework problem, we show a rating of the amount of effort we feel it will require:

◆ Should require just a few minutes. Little or no programming required.


◆◆ Might require up to 20 minutes. Often involves writing and testing some
code. (Many of these are derived from problems we have given on exams.)
◆◆◆ Requires a significant effort, perhaps 1–2 hours. Generally involves writ-
ing and testing a significant amount of code.
◆◆◆◆ A lab assignment, requiring up to 10 hours of effort.

Each code example in the text was formatted directly, without any manual
intervention, from a C program compiled with gcc and tested on a Linux system.
Of course, your system may have a different version of gcc, or a different compiler
altogether, so your compiler might generate different machine code; but the
overall behavior should be the same. All of the source code is available from the
CS:APP Web page (“CS:APP” being our shorthand for the book’s title) at csapp
.cs.cmu.edu. In the text, the filenames of the source programs are documented
in horizontal bars that surround the formatted code. For example, the program in
Figure 1 can be found in the file hello.c in directory code/intro/. We encourage
you to try running the example programs on your system as you encounter them.
To avoid having a book that is overwhelming, both in bulk and in content, we
have created a number of Web asides containing material that supplements the
main presentation of the book. These asides are referenced within the book with
a notation of the form chap:top, where chap is a short encoding of the chapter sub-
ject, and top is a short code for the topic that is covered. For example, Web Aside
data:bool contains supplementary material on Boolean algebra for the presenta-
tion on data representations in Chapter 2, while Web Aside arch:vlog contains
22 Preface

material describing processor designs using the Verilog hardware description lan-
guage, supplementing the presentation of processor design in Chapter 4. All of
these Web asides are available from the CS:APP Web page.

Book Overview
The CS:APP book consists of 12 chapters designed to capture the core ideas in
computer systems. Here is an overview.

Chapter 1: A Tour of Computer Systems. This chapter introduces the major ideas
and themes in computer systems by tracing the life cycle of a simple “hello,
world” program.
Chapter 2: Representing and Manipulating Information. We cover computer arith-
metic, emphasizing the properties of unsigned and two’s-complement num-
ber representations that affect programmers. We consider how numbers
are represented and therefore what range of values can be encoded for
a given word size. We consider the effect of casting between signed and
unsigned numbers. We cover the mathematical properties of arithmetic op-
erations. Novice programmers are often surprised to learn that the (two’s-
complement) sum or product of two positive numbers can be negative. On
the other hand, two’s-complement arithmetic satisfies many of the algebraic
properties of integer arithmetic, and hence a compiler can safely transform
multiplication by a constant into a sequence of shifts and adds. We use the
bit-level operations of C to demonstrate the principles and applications of
Boolean algebra. We cover the IEEE floating-point format in terms of how
it represents values and the mathematical properties of floating-point oper-
ations.
Having a solid understanding of computer arithmetic is critical to writ-
ing reliable programs. For example, programmers and compilers cannot re-
place the expression (x<y) with (x-y < 0), due to the possibility of overflow.
They cannot even replace it with the expression (-y < -x), due to the asym-
metric range of negative and positive numbers in the two’s-complement
representation. Arithmetic overflow is a common source of programming
errors and security vulnerabilities, yet few other books cover the properties
of computer arithmetic from a programmer’s perspective.
Chapter 3: Machine-Level Representation of Programs. We teach you how to read
the x86-64 machine code generated by a C compiler. We cover the ba-
sic instruction patterns generated for different control constructs, such as
conditionals, loops, and switch statements. We cover the implementation
of procedures, including stack allocation, register usage conventions, and
parameter passing. We cover the way different data structures such as struc-
tures, unions, and arrays are allocated and accessed. We cover the instruc-
tions that implement both integer and floating-point arithmetic. We also
use the machine-level view of programs as a way to understand common
code security vulnerabilities, such as buffer overflow, and steps that the pro-
Preface 23

Aside What is an aside?


You will encounter asides of this form throughout the text. Asides are parenthetical remarks that give
you some additional insight into the current topic. Asides serve a number of purposes. Some are little
history lessons. For example, where did C, Linux, and the Internet come from? Other asides are meant
to clarify ideas that students often find confusing. For example, what is the difference between a cache
line, set, and block? Other asides give real-world examples, such as how a floating-point error crashed
a French rocket or the geometric and operational parameters of a commercial disk drive. Finally, some
asides are just fun stuff. For example, what is a “hoinky”?

grammer, the compiler, and the operating system can take to reduce these
threats. Learning the concepts in this chapter helps you become a better
programmer, because you will understand how programs are represented
on a machine. One certain benefit is that you will develop a thorough and
concrete understanding of pointers.

Chapter 4: Processor Architecture. This chapter covers basic combinational and


sequential logic elements, and then shows how these elements can be com-
bined in a datapath that executes a simplified subset of the x86-64 instruction
set called “Y86-64.” We begin with the design of a single-cycle datapath.
This design is conceptually very simple, but it would not be very fast. We
then introduce pipelining, where the different steps required to process an
instruction are implemented as separate stages. At any given time, each
stage can work on a different instruction. Our five-stage processor pipeline is
much more realistic. The control logic for the processor designs is described
using a simple hardware description language called HCL. Hardware de-
signs written in HCL can be compiled and linked into simulators provided
with the textbook, and they can be used to generate Verilog descriptions
suitable for synthesis into working hardware.

Chapter 5: Optimizing Program Performance. This chapter introduces a number


of techniques for improving code performance, with the idea being that pro-
grammers learn to write their C code in such a way that a compiler can then
generate efficient machine code. We start with transformations that reduce
the work to be done by a program and hence should be standard practice
when writing any program for any machine. We then progress to trans-
formations that enhance the degree of instruction-level parallelism in the
generated machine code, thereby improving their performance on modern
“superscalar” processors. To motivate these transformations, we introduce
a simple operational model of how modern out-of-order processors work,
and show how to measure the potential performance of a program in terms
of the critical paths through a graphical representation of a program. You
will be surprised how much you can speed up a program by simple transfor-
mations of the C code.
24 Preface

Chapter 6: The Memory Hierarchy. The memory system is one of the most visible
parts of a computer system to application programmers. To this point, you
have relied on a conceptual model of the memory system as a linear array
with uniform access times. In practice, a memory system is a hierarchy of
storage devices with different capacities, costs, and access times. We cover
the different types of RAM and ROM memories and the geometry and
organization of magnetic-disk and solid state drives. We describe how these
storage devices are arranged in a hierarchy. We show how this hierarchy is
made possible by locality of reference. We make these ideas concrete by
introducing a unique view of a memory system as a “memory mountain”
with ridges of temporal locality and slopes of spatial locality. Finally, we
show you how to improve the performance of application programs by
improving their temporal and spatial locality.

Chapter 7: Linking. This chapter covers both static and dynamic linking, including
the ideas of relocatable and executable object files, symbol resolution, re-
location, static libraries, shared object libraries, position-independent code,
and library interpositioning. Linking is not covered in most systems texts,
but we cover it for two reasons. First, some of the most confusing errors that
programmers can encounter are related to glitches during linking, especially
for large software packages. Second, the object files produced by linkers are
tied to concepts such as loading, virtual memory, and memory mapping.

Chapter 8: Exceptional Control Flow. In this part of the presentation, we step


beyond the single-program model by introducing the general concept of
exceptional control flow (i.e., changes in control flow that are outside the
normal branches and procedure calls). We cover examples of exceptional
control flow that exist at all levels of the system, from low-level hardware ex-
ceptions and interrupts, to context switches between concurrent processes,
to abrupt changes in control flow caused by the receipt of Linux signals, to
the nonlocal jumps in C that break the stack discipline.
This is the part of the book where we introduce the fundamental idea
of a process, an abstraction of an executing program. You will learn how
processes work and how they can be created and manipulated from appli-
cation programs. We show how application programmers can make use of
multiple processes via Linux system calls. When you finish this chapter, you
will be able to write a simple Linux shell with job control. It is also your first
introduction to the nondeterministic behavior that arises with concurrent
program execution.

Chapter 9: Virtual Memory. Our presentation of the virtual memory system seeks
to give some understanding of how it works and its characteristics. We want
you to know how it is that the different simultaneous processes can each use
an identical range of addresses, sharing some pages but having individual
copies of others. We also cover issues involved in managing and manip-
ulating virtual memory. In particular, we cover the operation of storage
allocators such as the standard-library malloc and free operations. Cov-
Discovering Diverse Content Through
Random Scribd Documents
The signs have been divided into four triplicities, thus: fiery , ,
; earthy, , , ; airy, , , ; and watery, , , .

The bicorporal, or double-bodied, signs are , , and the first half


of . The fruitful signs are , , ; the barren signs are ,
, and .

These descriptions are useful in showing the modifications brought


to bear (by the sign ascending) on the planet's influence. But, when
no planets are in or near the ascendant at birth, the following
descriptions of the temperament and form of body produced by each
sign ascending at birth should be used.

Aries ( ) is a hot and fiery sign and produces a lean body, spare
and strong, large bones, grey eyes, with a quick glance and sandy or
red-coloured hair. The temper is violent. It governs the head and
face; its colour is white.

Taurus ( ) differs greatly, in its effects, from the preceding sign; it


is cold and dry, and gives a broad brow and thick lips. A person born
under it is melancholy and slow to anger but, when roused, furious
and difficult to be appeased. It governs the neck and throat; its
colour is red.

Gemini ( ) is in nature hot and moist and produces a person of


straight, tall body, sanguine complexion, brilliant eyes and light
brown hair. The temperament of those born under Gemini is lively
and the understanding good. This sign governs the arms and
shoulders; its colours are red and white.
Cancer ( ) is by nature cold and moist; it produces a native fair
and pale, short in stature, with a round face, sand-coloured brown
hair and grey eyes. Those born under it are phlegmatic, indolent and
gentle tempered. Women born under this sign generally have many
children. It governs the breast and stomach; its colours are green
and russet-brown.

Leo ( ) is a fiery, hot and dry sign. When it rises at birth without
any planet being near the ascendant, the native will be of tall
stature, with yellow hair, ruddy complexion and oval face, and he will
have a quick glance and a strong voice. It governs the heart, the
back and the neck; its colours are red and green.

Virgo ( ) is an earthy, cold, barren, feminine sign. When it


ascends, it shows a well-formed body, slender and tall, straight,
dark-brown hair and a round face. The mind of the native is
ingenious, but rather inconstant. It governs the belly; its colour is
black speckled with blue.

Libra ( ) is an aërial, sanguine, masculine, hot and moist sign.


Rising at birth it produces a well-made body, with long limbs, an oval
and beautiful face, sanguine complexion, straight flaxen hair and
grey eyes. Those born under it are courteous, just and honourable.
It governs the loins; and the colours under its rule are black,
crimson and tawny.

Scorpio ( ) is a moist, phlegmatic, feminine sign. It gives a strong,


corpulent body, low stature, thick legs, hair growing low on the
forehead and heavy eyebrows. Those born under this sign are
reserved, thoughtful, subtle and malicious. It governs the lower
parts of the body; the colour under its rule is brown.
Sagittarius ( ) is a fiery, masculine sign. The person born under its
rule is handsome, with a rather long face and features, chestnut hair,
inclined to baldness and ruddy complexion; the body strong and
active. Those born under this sign are fond of field sports, are good
riders, and are lovers of animals. They are kindly, generous and
careless of danger. This sign governs the thighs and hips, and rules
yellow and green.

Capricorn ( ) is an earthy, cold, dry, feminine sign. It produces a


person of slender stature, with a long neck, narrow chest and dark
hair. The mind is quick, witty and subtle. It governs the knees and
hams and, in colours, it rules black or dark brown.

Aquarius ( ) is an airy, moist, masculine sign. In a nativity where


no planets are in or near the ascendant, it would produce a person
of a well-set, strong body, long face and delicate complexion, with
brown hair. It governs the legs and ankles and rules the sky-colour
or blue.

Pisces ( ) is a watery, cold and feminine sign. It produces a person


of short stature and fleshy body, with a rather stooping gait. Those
born under its influence are indolent and phlegmatic. It governs the
feet and toes and presides over the pure white colour. It is needful
to remember the colours belonging to the signs, as they are
especially useful in horary questions.
CHAPTER IV.

OF THE NATURES OF THE SEVEN PLANETS AND OF THEIR ESSENTIAL AND


ACCIDENTAL DIGNITIES

Of the seven planets Jupiter and Venus, because of the heat and
moisture predominant in them, are considered by the ancients as
benefics or causers of good. The Moon is so considered for the same
reasons, though in a less degree.

Saturn and Mars are causers of evil or malefic; the first from his
excess of cold, and the other from his excess of heat. The Sun and
Mercury are deemed of common influence—that is, either of good or
evil, according to the planets with which they are connected.

The planets have particular familiarity with certain places in the


zodiac by means of parts designated as their houses, and also by
their triplicities, exaltations and terms.

The nature of their familiarity by houses is as follows:—

Cancer and Leo are the most northerly of all the twelve signs; they
approach nearer than the other signs to the zenith of this part of the
earth, and thereby cause warmth and heat; they are consequently
appropriated as houses for the two principal and greater luminaries;
Leo for the Sun, as being masculine; and Cancer for the Moon, as
being feminine.

Saturn, since he is cold and inimical to heat, moving also in a


superior orbit most remote from the luminaries, occupies the signs
opposite to Cancer and Leo; these are Aquarius and Capricorn, and
they are assigned to him in consideration of their cold and wintry
nature.
Jupiter has a favourable temperament, and is situated beneath the
sphere of Saturn; he, therefore, occupies the next two signs,
Sagittarius and Pisces.

Mars is dry in nature and beneath the sphere of Jupiter; he takes the
next two signs, of a nature similar to his own, viz., Aries and Scorpio,
whose relative distances from the houses of the luminaries are
injurious and discordant.

Venus, possessing a favourable temperament, and, placed beneath


the sphere of Mars, takes the next two signs, Taurus and Libra.
These are of a fruitful nature and preserve harmony by the sextile
distance; this planet is never more than two signs distant from the
Sun.

Mercury never has greater distance from the Sun than the space of
one sign, and is beneath all the other planets; hence he is nearest to
both luminaries, and the remaining two signs, Gemini and Virgo, are
allotted to him.

The "houses" of the planets are readily shown by the following table.
It is exactly the same as that found in the mummy-case of the
Archon of Thebes, in ancient Egypt, as may be seen at the British
Museum:
It will be seen, at once, from this table that the Sun and Moon have
each only one house assigned them. All planets are most powerful in
that sign which constitutes one of their houses. Planets receive
detriment in the signs opposite to those of their houses. Thus,
Saturn would receive detriment in Cancer and Leo, which are the
signs opposite to his houses, Capricornus and Aquarius. There are
some signs in which the planets are found to be very powerful,
though not to the same extent as when in their own houses; these
are called the "exaltations" of the planets, and the signs opposite to
these are those in which they receive their "fall" when they are
considered to be weak in power. Saturn has his exaltation in Libra;
his "fall" would therefore be in Aries. He governs the airy triplicity,
which is composed of the signs Gemini, Libra and Aquarius by day,
and in all the twelve signs he has these degrees (zodiacal signs)
allotted him by Ptolemy for his Terms:

In Aries 27, 28, 29, 30.


In Taurus 23, 24, 25, 26.
In Gemini 22, 23, 24, 25.
In Cancer 28, 29, 30.
In Leo 1, 2, 3, 4, 5, 6.
In Virgo 19, 20, 21, 22, 23, 24.
In Libra 1, 2, 3, 4, 5, 6.
In Scorpio 28, 29, 30.
In Sagittarius 21, 22, 23, 24, 25.
In Capricornus 26, 27, 28, 29, 30.
In Aquarius 1, 2, 3, 4, 5, 6.
In Pisces 27, 28, 29, 30.

The meaning of which is that if Saturn should rise in any of these


degrees it is a sign that he is not void of essential dignities; or, if he
is posited in any of the following degrees (which he is allowed for his
Face or Decanate) he is still not devoid of dignities. This is to be
understood of all the planets.

Saturn is allotted for his Face these degrees:

In Taurus 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Leo 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Libra 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Sagittarius 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Pisces 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.

Jupiter has his exaltation in Cancer and his fall in Capricornus. He


rules the fiery triplicity, Aries, Leo and Sagittarius, by night.

He has these degrees allotted for his Terms:

In Aries 1, 2, 3, 4, 5, 6.
In Taurus 16, 17, 18, 19, 20, 21, 22.
In Gemini 8, 9, 10, 11, 12, 13, 14.
In Cancer 7, 8, 9, 10, 11, 12, 13.
In Leo 20, 21, 22, 23, 24, 25.
In Virgo 14, 15, 16, 17, 18.
In Libra 12, 13, 14, 15, 16, 17, 18, 19.
In Scorpio 7, 8, 9, 10, 11, 12, 13, 14.
In Sagittarius 1, 2, 3, 4, 5, 6, 7, 8.
In Capricornus 13, 14, 15, 16, 17, 18, 19.
In Aquarius 21, 22, 23, 24, 25.
In Pisces 9, 10, 11, 12, 13, 14.

He has for his Face, or Decanate:

Of Gemini 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
Of Leo 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
Of Libra 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
Of Capricornus 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
Of Pisces 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.

Mars has Aries for his day-house and Scorpio for his night-house. He
is exalted in Capricornus, and has his fall in Cancer.

He governs the watery Triplicity, viz., Cancer, Scorpio and Pisces, and
he has these degrees in each sign for his Terms:

In Aries 22, 23, 24, 25, 26.


In Taurus 27, 28, 29, 30.
In Gemini 26, 27, 28, 29, 30.
In Cancer 1, 2, 3, 4, 5, 6.
In Leo 26, 27, 28, 29, 30.
In Virgo 25, 26, 27, 28, 29, 30.
In Scorpio 1, 2, 3, 4, 5, 6.
In Aquarius 26, 27, 28, 29, 30.
In Pisces 21, 22, 23, 24, 25, 26.

He has allotted to him for his Face these degrees:

In Aries 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Gemini 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Leo 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Virgo 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Pisces 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.

The Sun rules the fiery Triplicity—Aries, Leo and Sagittarius—by day.
He is exalted in the sign of Aries, and receives his fall in Libra.

He has no degrees admitted him for his Terms, but in the twelve
signs he has the following degrees for his Face:

In Aries 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Gemini 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Virgo 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Scorpio 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Capricornus 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.

Venus governs the earthy Triplicity—Taurus, Virgo and Capricornus—


by day. She is exalted in Pisces, and has her fall in Virgo. She has
the following degrees for her Terms:

In Aries 7, 8, 9, 10, 11, 12, 13, 14.


In Taurus 1, 2, 3, 4, 5, 6, 7, 8.
In Gemini 15, 16, 17, 18, 19. 20.
In Cancer 21, 22, 23, 24, 25, 26, 27.
In Leo 14, 15, 16, 17, 18, 19.
In Virgo 8, 9, 10, 11, 12, 13.
In Libra 7, 8, 9, 10, 11.
In Scorpio 15, 16, 17, 18, 19, 20, 21.
In Sagittarius 9, 10, 11, 12, 13, 14.
In Capricornus 1, 2, 3, 4, 5, 6.
In Aquarius 13, 14, 15, 16, 17, 18, 19, 20.
In Pisces 1, 2, 3, 4, 5, 6, 7, 8.

The following degrees are allowed for her Face:

In Aries 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Cancer 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Virgo 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Scorpio 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Pisces 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.

Mercury governs the airy Triplicity, viz., Gemini, Libra and Aquarius,
by night. He has his exaltation in Virgo, and his fall in Pisces. He has
the following degrees for his Terms:

In Aries 15, 16, 17, 18, 19, 20, 21.


In Taurus 9, 10, 11, 12, 13, 14, 15.
In Gemini 1, 2, 3, 4, 5, 6, 7.
In Cancer 14, 15, 16, 17, 18, 19, 20.
In Leo 7, 8, 9, 10, 11, 12, 13.
In Virgo 1, 2, 3, 4, 5, 6, 7.
In Libra 20, 21, 22, 23, 24.
In Scorpio 22, 23, 24, 25, 26, 27.
In Sagittarius 15, 16, 17, 18, 19, 20.
In Capricornus 7, 8, 9, 10, 11, 12.
In Pisces 15, 16, 17, 18, 19, 20.

These degrees are assigned him for his Face:

In Taurus 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Cancer 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Virgo 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Sagittarius 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Aquarius 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.

The Moon governs the earthy Triplicity, viz., Taurus, Virgo and
Capricornus, by night.

She is exalted in Taurus, and has her fall in Scorpio. The Sun and the
Moon have no terms assigned them.

In the twelve signs she has these degrees assigned her for her Face:

In Taurus 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Cancer 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Libra 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Sagittarius 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Aquarius 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
A planet in his fall is very weak in his influence. The Houses count
first in dignity, then the Exaltation; afterwards the Triplicity, the
Terms, and the Faces.

The meaning of this is, if a planet is in any of the signs we call his
house or houses, he is essentially strong, and he is allowed five
dignities.

If he is in the sign in which he is said to be exalted, he is allowed


four dignities.

If he should be placed in any of the signs allowed him for his


Triplicity, he is allowed three dignities.

If in any of the degrees in the signs which are given as his Terms, he
has two dignities.

If in any of the degrees of the sign given to him as his Face, he is


allowed one essential dignity. Accidental dignities are when a planet
is swift in motion, angular or in sextile aspect with Jupiter or Venus.

There was a great difference between the Arabian, Indian, and


Greek methods in the disposing of the degrees of the sign to each
planet until the time of Ptolemy. Since then almost all astrologers
followed the method he left, which is that which has been given in
this chapter.
CHAPTER V.

OF THE INFLUENCES OF THE SEVEN PLANETS

The planet Saturn is the most remote of the seven planetary orbs
recognised by the ancient writers on astrology. He is of a pale ash
colour, slow in motion, only finishing his course through the twelve
signs of the zodiac in 29 years and about 157 days. His greatest
north latitude from the ecliptic is 2 degrees 48 minutes; his south
latitude is 2 degrees 49 minutes.

Those born with this planet well-dignified [4] are studious, grave,
economical, prudent, patient and in all their actions sober and
somewhat austere. They are not much given to the love of women,
but they are persons of much depth of feeling, and, when they do
love, they are very constant. They are given to the study of occult
matters, [5] and are of a melancholic, suspicious and jealous
temperament. In person when well-dignified Saturn gives a rather
tall stature and long limbs. The hair is dark, the eyebrows much
marked and generally meeting between the eyes, which are dark
brown, deep set and close together. The nose is long and generally
somewhat bent over the lips and the under jaw slightly protrudes.
The complexion is sallow, the ears large and the hands and feet are
generally long, but not fleshy.

Those born under the potent aspect of Saturn are generally slow of
speech and their voices are harsh; when Saturn rises in a horoscope
devoid of dignities, the native is envious, covetous, malicious, subtle,
untruthful and of a discontented disposition. In person frequently
deformed, with long and irregular features, the eyes and hair dark
and the skin yellow and harsh.
In man's body this planet rules the spleen, the right ear, the lips and
the teeth. In illness he gives ague, palsy, ruptures (especially should
he rule in the sign of Scorpio), jaundice, toothache and all affections
of the sight, of the ear, of the teeth and jaws and of the legs.

The herbs he governs are the hemlock, hellebore, burdock, sage,


henbane, rue, nightshade and mandrake.

The trees under his rule are the willow, the yew, the cypress, the
box-tree and the pine.

The beasts he governs are the elephant, the wolf, the bear, the dog,
[6] the basilisk, the crocodile, the scorpion, the serpent, the rat, the
mouse and all manner of creeping things; among birds, the crow,
the cuckoo, the raven, the owl and the bat.

Of fish he rules the eel, the tortoise and all shell fish.

The minerals he governs are lead and the dross of all metals.

His stones are jet, onyx and all dark stones which are incapable of
polish. The colour he rules is black.

He rules Saturday—the first hour after sunrise, and the eighth hour
of the same day. His number is 55. In gathering the herbs under his
rule the ancients were particular to do so in his hours, as this
rendered the medicament more powerful. This is to be observed
regarding the herbs ruled by all the planets.

Saturn's orb is nine degrees before and after any aspect; that is, his
influence begins to operate when either he applies to any planet or it
applies to him within nine degrees of his perfect aspect, and his
influence continues in force until he is separated nine degrees from
the aspect. His angel is Cassiel. His friends are Jupiter, Venus,
Mercury and the Moon; his enemies are Mars and the Sun.
Jupiter is the next planet below Saturn and is of a bright, clear, azure
colour. He much exceeds Saturn in motion, as he finishes his course
through the twelve signs in twelve years. His greatest north latitude
is 1 degree 38 minutes, and his greatest south latitude 1 degree 40
minutes. When he rises at birth well-dignified he gives an erect, tall
stature, sanguine complexion, oval face, large grey eyes, thick
brown hair, full lips and good teeth. In temperament those born
under the good influence of this planet are honourable, generous
and hospitable, but loving material pleasures, kind and affectionate
to wife and family, charitable, desiring to be well thought of and
hating all mean and sordid actions. The voices of those born under
Jupiter are clear and sonorous. When this planet rises devoid of
dignities the native will be gluttonous, profligate, vain, and boastful,
of mean abilities and shallow understanding, easily seduced to
extravagance and a tyrant to those of his family and household.

In man's body he rules the lungs and the blood, and of diseases he
gives apoplexy, gout, inflammation of the lungs, pleurisy and all
illnesses proceeding from corruption of the blood.

The herbs he governs are cloves, mace, nutmeg, gilliflower,


marjoram, mint, borage and saffron.

Of trees, he rules the mulberry, the olive, the vine, the fig, the beech
and the pear-tree.

Of beasts, the sheep, the hart, the ox and all those animals that are
useful to man.

Of birds, the stork, the snipe, the lark, the eagle, the pheasant, the
partridge and the peacock.

Of fishes, the whale, the dolphin and the sword-fish.

His metal is tin.

His stones are the sapphire, the amethyst and the emerald.
Of colours he rules red mixed with green.

His day is Thursday and he rules the first hour after sunrise and the
eighth hour. His number is 78.

His orb is 9 degrees before and after any aspect.

All the planets except Mars are his friends.

His angel is Zadkiel.

Mars in order succeeds Jupiter. He appears of a red colour, and


finishes his course through the zodiac in 1 year 321 days. His
greatest north latitude is 4 degrees 31 minutes. His south latitude is
6 degrees 47 minutes. When he is well-dignified in a horoscope, the
native is courageous, confident, loving war and all that belongs to it,
jealous of honour, hot-tempered and a great lover of field-sports. In
person he will be of middle stature, broad-shouldered and with big
bones; the complexion of a red fairness; the hair is crisp or curly and
also red, but this varies slightly according to the sign rising at birth;
in watery signs the hair is not so red, and in earthy signs it is more
chestnut; the eyes are grey and have a bold, fixed glance like that of
a hawk.

When he is ill-dignified at birth, the native is turbulent, cruel,


boastful, a promoter of sedition, ungracious in manners and
unscrupulous in his actions, with no fear of either God or man. He
rules the head and face, the gall, the throat and intestines; and the
diseases he gives are fevers, carbuncles, smallpox, all throat
affections, all hurts to the head and face (especially by iron), and all
diseases which arise from too much heat of blood; also accidents
from four-footed beasts.

The herbs over which he rules are the nettle, the thistle, onions,
scammony, garlic, horehound, cardamons, mustard and all herbs
giving heat.
Of trees, all those which are of a prickly nature, such as the holly,
the thorn and the chestnut.

Of beasts, all fierce animals—the tiger, the panther, the wolf, the
horse, the leopard, the wild ass and the bear.

The dog is sometimes assigned to Mars on account of its courage


and combativeness. This delightful animal is probably ruled by both
Saturn and Mars; the former giving it the quality of fidelity which it
possesses in a degree beyond all other creatures.

Of fish, the pike, the barbel and the sword-fish.

Of birds, the hawk, the vulture, the kite, the eagle, the magpie and
the cock, all of which are combative.

The metal he rules is iron. The colour he rules is red.

The stones, the carbuncle, the ruby and the blood-stone.

His orb is 7 degrees before and after any aspect.

He governs Tuesday—the first hour after sunrise, and the eighth. His
number is 39.

His friend among the planets is Venus, all the others are his
enemies.

His angel is Samael.

The Sun passes through all the twelve signs of the zodiac in one
year and a few hours over the 365 days which constitute the year.
He has no latitude.

When the Sun rises at a birth well-dignified, the native is of an


honourable disposition, but always desiring to rule, loving pomp, yet
affable, speaking with gravity and without too many words and
possessing much self-reliance and dignity of manner. In person he
will be tall, well made, with golden hair, yellowish skin, large and
piercing eyes and long, straight and well-formed features.

When ill-aspected the native is arrogant, boastful, a spendthrift,


proud, yet in poverty hanging on other men's charity, very
loquacious, restless and without judgment.

He governs the heart, the brain, the right eye and the arms; and the
diseases he causes are all illnesses of the heart, such as swoons,
palpitations, cramps, also diseases of the mouth, the brain, and the
eyes.

Of colours he rules the yellow and orange colour.

The plants subject to the Sun are all those of pungent odours, such
as the marigold, heliotrope, rosemary, balsam, peony, spikenard,
musk, St. John's wort, and ginger.

Of trees he rules the palm, the laurel, the cedar, the orange-tree and
the citron-tree.

Of beasts, the lion, the ram, the goat.

Of birds, the eagle, the cock, the buzzard.

Of fish, the star-fish, the crab-fish and the sea-fox.

He governs Sunday. His number is 34.

Of metals, gold.

Of colours he rules the yellow.

Of stones, the topaz, amber, chrysolite and all yellow stones.

His orb is 15 degrees before any aspect, and as many after


separation.

His friends are all the planets except Saturn and Mars.
His angel is Michael.

After the Sun the planet Venus succeeds in order; she is of a bright
shining colour. Her greatest north or south latitude is 2 degrees and
2 minutes. When she rises well-dignified in a nativity the person
born will be of middle stature, rather inclining to shortness, with a
beautiful complexion, light brown hair, the eyes large, of a blue or
grey colour and with a slow and rather languishing movement, red
lips, and dimples in the cheeks, chin and about the mouth. In
disposition, gracious, very tender, inclined to love-making; easy of
belief and not given to labour about anything; fond of music, plays,
and all sorts of merry-makings.

When ill-dignified at birth Venus causes the native to be over-fat,


with thick lips, and much flesh about the chin and cheeks. In
disposition, sensual, riotous and immoral.

Venus governs the lower parts of the body, and the illnesses she
gives are cancer and all affections of the womb.

All the herbs she governs have a sweet smell and, generally, have
smooth leaves and white flowers, such as the lily, both white and
yellow, and the lily of the valley, also the water lily, the myrtle,
maidenhair, violets and roses.

The trees she rules are the walnut, the almond, the apple-tree, the
box-tree, the sycamore, the ash and myrtle.

Of beasts, the hart, the rabbit, the calf and all small cattle.

Of birds, the dove, the sparrow, the nightingale, the swan, the
pelican and the swallow.

Her metal is copper.

Her stones, white and red coral, rubies, the beryl, turquoise and
lapis lazuli, because it expels melancholy.
Her colours are white and purple.

Her orb is 7 degrees before and after any aspect.

Her day of the week is Friday, of which she rules the first and eighth
hour after sunrise. Her number is 45.

Her friends are all the planets, but Saturn is the least sympathetic to
her.

Her angel is Anael.

Mercury is of a soft silver colour. His greatest north latitude is 3


degrees 33 minutes. His greatest south latitude is 3 degrees 33
minutes.

When he rises well-dignified at a birth the native is a person of


subtle intellect, an excellent logician, and possessing much
eloquence in his speech; sharp and witty, of admirable memory,
curious in occult knowledge, given to divination, and, if he should
turn his attention to trade, no man would exceed him in the
invention of new ways to gain wealth.

In person, when Mercury rises well-dignified, the native is of rather


small stature, but elegantly formed, very active and supple in his
limbs, and with long arms; he will have a long, narrow face, a high
forehead, rather swelling at the temples, grey eyes with brown spots
in them, delicate mouth, straight eyebrows, a skin of a pale yellow
or olive colour, the hair of a red-brown, commonly called auburn.

When ill-dignified at birth Mercury gives a person of very small


stature, with small, insignificant features and very small and quickly-
moving eyes; and in character he is shifty, a boaster, foolishly
loquacious and a great liar.

He rules the liver, the tongue and the nerves, and the illnesses he
gives are epilepsy, giddiness, dry cough, any affection of the tongue,
and all nervous affections.

The herbs attributed to him are generally those having a subtle


smell, and having effect on the tongue, brain, lungs, or memory;
they are vervain, adder's-tongue, aniseed, dragon-wort, and the
reed.

The trees are the elder and the filbert-tree.

The animals are the squirrel, the weasel, the spider, the greyhound,
the fox, the ape and all cunning and quickly-moving creatures.

The birds, the parrot, the magpie, the crane, the linnet and the
swallow.

Of fish, the jack-fish and the mullet.

His metal is quicksilver.

His stones all those of divers colours, white and red carnelian and
marcasite, or fire-stone.

In colours he rules azure, and all light blue colours.

His orb is 7 degrees before and after any aspect.

He governs Wednesday—the first hour and the eighth after sunrise.


His number is 114. The Moon, Venus, Jupiter, the Sun and Saturn
are his friends; Mars is his enemy.

His angel is Raphael.

The Moon is the nearest to the earth of all the seven planets. She
finishes her course through the whole twelve signs in 27 days 7
hours and 36 seconds. Her greatest north latitude is 5 degrees and
about 17 minutes, her greatest south latitude 5 degrees and 12
minutes.
When she rises well-placed in a horoscope, she signifies a person of
soft and gentle manners, timid, imaginative, loving pleasure and
ease, yet fond of moving from place to place, rather capricious, but
of a poetic and romantic turn of mind. In person, those born under
good aspects of the Moon are of middle height, with a round head
and face, pale, soft skin, large light eyes, usually one a little larger
than the other. The whole body inclined to be fleshy, the lips full,
and the hair of a dull, light colour, but not at all inclined to gold.

When the Moon is ill-aspected at birth the native is indolent,


sometimes a drunkard and vagabond, generally a liar, and, as Lilly
puts it, "a muddling creature."

The Moon governs the left side and the bladder. She gives dropsy, all
cold and rheumatic diseases, colds or hurts in the eyes, convulsive
fits, hysteria, and feminine weaknesses.

The plants she governs are all those which have soft, juicy leaves,
such as the lettuce, the melon, the gourd, the poppy, mushroom,
cabbage and colewort. Of trees, all those which have round,
spreading leaves, such as the lime-tree and the sycamore.

The beasts she rules are those which love the water, as the otter
and the seal.

She rules all sea fowl and also the goose, the duck and the night
owl.

Of fish, the oyster, the cockle and the lobster.

Her colours are light greenish-blue mixed with white.

Her metal is silver.

Her stones, pearls, diamonds, opals, crystals and selenite.

Her orb is 12 degrees before and after any aspect.


Her day is Monday; the first hour and the eighth after sunrise are
hers. Her number is 45.

Her friends are Venus, Jupiter, the Sun, Saturn and Mercury.

Her enemy among the planets is Mars.

Her angel is Gabriel.

To face Chapter VI.


CHAPTER VI.

CONCERNING THE TWELVE HOUSES OF HEAVEN AND THEIR POWERS

The ancient astrologers divided the heavens into twelve houses.

The First House.—This is called the Ascendant, and the planet rising
therein—whether well or ill-dignified—will materially affect the mind,
bodily appearance and fate of the native through his whole
existence. This house is masculine, and governs the head and face
of man and, if the planet Mars be in this house at the time of birth,
there will always be some blemish or mole in the face of the native;
if a few out of the degrees have ascended the scar or blemish is,
without fail, on the upper part of the head; if the middle part of the
sign ascends the mark is in the middle of the face; if the latter part
of the sign is ascending the mark is near the chin. This house
represents the head, the tongue and the memory, and it governs in
colours white.

The Second House.—This house has signification of the native's


wealth and worldly goods. The house is feminine, ruling the neck,
and the colour is green.

The Third House.—This governs brothers and sisters, short journeys,


neighbours, letters and writings. It is masculine and governs the
hands, arms and shoulders; its colours are red and yellow mixed.

The Fourth House.—This rules the father, inheritances or property of


the native, and shows his condition at the close of life. It is feminine,
and rules the stomach, breast and lungs; its colour is red.

The Fifth House.—This signifies the children of the native, also his
success in speculation and hazardous games, the pleasures he
enjoys and the wealth of the father. It rules the heart, back and liver,
is masculine, and represents in colour black and white mixed.

The Sixth House.—This concerns the native's servants, sheep, goats


and small cattle. It also signifies the father's kindred. This house is
feminine. It rules the belly and intestines and its colour is black.

The Seventh House gives judgment of marriage and describes the


man or woman in all love questions. It is masculine, it rules the
haunches, and its colour is black.

The Eighth House argues of death, of legacies and wills, also of the
kind of death a man shall die; it is a feminine house. It rules the
lower parts of the trunk of the body; its colours are green and black.

The Ninth House gives judgment on voyages and long journeys, and
also on events happening to the wife's kindred. It rules the hips and
thighs. It is a masculine house; its colours are green and white.

The Tenth House is called the Mid-heaven, and is feminine. This


concerns the native's mother, and also his calling. It rules the knees
and hams, and its colours are red and white.

The Eleventh House represents friends and friendship. It is


masculine and rules the legs.

The Twelfth House.—This house is often called the Evil Dæmon, for
it is the house of sorrow, self-undoing, enemies and imprisonment.
It governs great cattle. It is feminine, and rules the feet and toes,
and in colour it governs green.

The strongest houses are the first (the Ascendant) and the tenth
(the Mid-heaven). The first, fourth, seventh, and tenth are called
Angular Houses, and represent the four cardinal points of the
compass; thus the first is east, the seventh west, the fourth is north,
and the tenth south. The second, fifth, eighth, and eleventh houses
are called Succedent Houses; the third, sixth, ninth, and twelfth
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about testbank and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebooksecure.com

You might also like