100% found this document useful (1 vote)
20 views

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

The document provides information about various eBook titles available for instant download at ebookluna.com, including editions on computer systems and health informatics. It highlights the benefits of these resources for students and offers direct links for access. Additionally, it mentions the global editions of certain textbooks tailored for international students.

Uploaded by

harisitjizoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
20 views

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

The document provides information about various eBook titles available for instant download at ebookluna.com, including editions on computer systems and health informatics. It highlights the benefits of these resources for students and offers direct links for access. Additionally, it mentions the global editions of certain textbooks tailored for international students.

Uploaded by

harisitjizoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Quick and Easy Ebook Downloads – Start Now at ebookluna.

com for Instant Access

(eBook PDF) Computer Systems: A Programmer's


Perspective 3nd Edition

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

OR CLICK BUTTON

DOWLOAD EBOOK

Instantly Access and Download Textbook at https://ebookluna.com


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

(eBook PDF) Health Informatics: A Systems Perspective, Second Edition

https://ebookluna.com/product/ebook-pdf-health-informatics-a-systems-
perspective-second-edition/

(eBook PDF) Health Informatics: A Systems Perspective First Edition

https://ebookluna.com/product/ebook-pdf-health-informatics-a-systems-
perspective-first-edition/

(eBook PDF) Comparative Health Systems: A Global Perspective 2nd Edition

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

CMOS VLSI Design A Circuits and Systems Perspective (4th Edition)

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

https://ebookluna.com/product/ebook-pdf-computer-systems-5th-edition/

Computer Systems 5th Edition (eBook PDF)

https://ebookluna.com/product/computer-systems-5th-edition-ebook-pdf/

(eBook PDF) Health Care Operations Management: A Systems Perspective 2nd


Edition

https://ebookluna.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://ebookluna.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://ebookluna.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
Visit https://testbankfan.com
now to explore a rich
collection of testbank or
solution manual and enjoy
exciting offers!
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
Discovering Diverse Content Through
Random Scribd Documents
CHAPTER FOUR
Out on the end of the long pier that juts far into the Saint
Lawrence, Nancy Howard was idly tossing scraps of paper into the
choppy surface of the mighty river. Behind her, Sainte Anne-de-
Beaupré was rapidly putting on her winter guise. The last pilgrimage
ended, the good saint lost no time in packing up her relics for safe
keeping, until the next year’s pilgrims should turn their faces
towards her shrine. Nancy had returned from the telegraph office,
two days before, past rows of dismantled booths and of shops
whose proprietors were already taking inventory of their remaining
possessions. The heaped-up missals and rosaries made little
impression upon her; but even her stalwart Protestantism rebelled at
sight of the bare-armed priestess who was scrubbing a plaster Virgin
with suds and a nailbrush. Nancy would have preferred the more
impersonal cleansing administered by the garden hose.
Even Nancy Howard had been forced to admit that the Good
Sainte Anne had earned her money. Excitement had not been
lacking, during the past two days. It was one thing to come to her
father’s aid with an offer to play nurse; it was quite another matter
to give several hours of each day to the whims of a man who was as
unused to pain as he was to the thwarting of his plans. Nancy had
expected a playful bit of masquerade. She promptly discovered that
she was doomed to work as she had never worked before. She had
informed Barth that it was her custom to leave all financial
arrangements in the hands of the doctor. She had no idea what
value it might have pleased her father to set upon her services. She
had a very distinct idea, however, that, whatever the value, she fully
earned it. Arrogant and desponding, masterful and peevish by turns,
Cecil Barth was no easy patient. Accustomed all his life to being
served, he now had less notion than ever of lifting a finger to serve
himself. Moreover, Nancy Howard had a rooted objection to being
smoked at. Her objection was based upon chivalry, not antipathy to
nicotine; nevertheless, it was active and permanent. She only
regained her lost poise, when she tried to reduce to systematic
orthography the unspellable accent of her patient, most of all that
prolonged Oh-er, raahther! which appeared to represent his
superlative degree of comparison.
“Oh, nurse?”
Barth’s voice met her on the threshold, as, capped with a bit of
lawn and covered with an ample apron from the wardrobe of
Madame Gagnier, she opened the door of the invalid’s room.
“Yes, sir.”
“I thought you would never come back.”
“You have needed something?”
“Yes. The room is too warm, and I think it is time for the
rubbing.”
“Not for fifteen minutes,” Nancy answered calmly. “I told you I
would be back in time.”
“Yes. But it is so warm here.”
“Why didn’t you call Madame Gagnier to open a window?”
“Because she is so very clumsy. Please open it now.”
Nancy repressed a sudden longing to cross the room on her
heels. Barth was sitting up, that day; but the lines around his lips
and the brilliant patch of scarlet on either cheek betrayed the fact
that the past two days had worn upon him.
“Is your foot aching now?” she asked, as she returned to her
seat.
“Yes, intensely. Do you suppose that doctor knows how to treat
it?”
Nancy’s eyes flashed.
“He ought to,” she answered shortly.
Barth turned argumentative.
“It is not a question of obligation; it is a mere matter of training
and experience,” he observed.
“He is the best doctor in the city,” Nancy persisted.
“In Quebec?”
“No; at home.”
For the dozenth time since his catastrophe, Barth regretted the
loss of his glasses. Nancy’s tone betrayed her irritation. Unable to
see her face distinctly, he was also unable to fathom the cause of
her displeasure. He peered at her dubiously for a moment; then he
dropped back in his chair.
“Very likely,” he agreed languidly. “Now will you please move the
foot-rest a very little to the right?”
“So?”
“Yes. Thank you, nurse.”
“Is there anything else?”
He pointed to the table at his elbow.
“My pipe, please; and then if you wouldn’t mind reading aloud for
a time.”
Nancy did mind acutely; but she took up the book with an
outward showing of indifference, while Barth composed himself to
smoke and doze at his pleasure.
For a long hour, Nancy read on and on. Now and then she
glanced out at the sunshiny lawn beneath the window; now and
then she looked up at her patient, wondering if he would never bid
her cease. In spite of her rebellion at her captivity, however, she was
forced to admit that Barth had his redeeming traits. His faults were
of race and training; his virtues were his own and wholly likable.
Moreover, in all essential points, he was a gentleman to the very
core of his soul and the marrow of his bones.
“‘Still of more moment than all these cures, are the graces which
God has given, and continues to give every day, through the
intercession of good Sainte Anne, to many a sinner for conversion to
better life.’” Nancy’s quiet contralto voice died away, and M. Morel’s
old story dropped from her hands. Barth’s eyes were closed, and she
decided that he had dropped to sleep; but his voice showed her
mistake.
“It’s a queer old story. Do you believe it all, nurse?”
A sudden spice of mischief came into Nancy’s tone.
“Yes, and no. I doubt the epilepsy and paralysis; it remains to be
seen about the conversions to a better life.”
“I suppose one could tell by following up the cases,” Barth said
thoughtfully.
“Certainly.” Nancy’s accent was incisive. “I accept nothing on
trust.”
Barth took a prolonged pull at his pipe.
“But it’s not so easy to follow up cases two hundred and fifty
years old,” he suggested.
Nancy laughed.
“No; I’ll content myself with the modern ones.”
“Do you suppose there are any modern ones?”
“Oh, yes. The priests claim that there are several new cases,
every year.”
“And you can get on the track of them?” he asked, with a sudden
show of interest.
“Surely. I have my eye on one of them now,” Nancy responded
gravely.
“A Sainte Anne miracle?”
“Yes.”
“Tell me where it is?” he urged.
She shook her head.
“I can’t. It concerns somebody besides myself,” she replied, with
a decision which he felt it would be useless to question.
There was a prolonged pause. It was Barth who broke it.
“Strange we never heard of the place at home!” he said
reflectively.
“How long since you came here?” Nancy asked, rather
indifferently.
“Two weeks.”
“And you like it?”
“For a change. It is a change from the ’Varsity, though.”
“Which was your university?” she inquired, less from any interest
in the answer than because she could see that her patient was in an
autobiographical frame of mind, and even her brief experience of
mankind had taught her to let such moods have their way.
“Kings, at Cambridge. I was at Eton before that.”
“What sent you out here?”
“Ranching. My brother went in for the army, and we didn’t care
to have two of a kind in the same family.”
“It might be a little monotonous,” she assented gravely. “But
where is your ranch?”
“I haven’t any yet. I am stopping in Quebec for the winter, and I
shall go out, early in the spring.”
“Is Quebec a pleasant place?” she asked, as she crossed the
room to the window and stood looking out at the river beneath.
“It’s rather charming, only I don’t know anybody there.”
“Why don’t you get acquainted, then?”
“How can I? I brought some letters; but the people have moved
to Vancouver.”
“Yes; but they aren’t the only people in Quebec.”
“Of course not; but I don’t know any of the others.”
“But you can?”
“How?” Barth queried blankly.
“Why, talk to them, do the things they do—oh, just get
acquainted; that’s all,” the girl answered, with some impatience.
He raised his brows inquiringly. It was not the first time that
Nancy had been annoyed by the expression.
“Talk to people, before you have been introduced to them?”
“Yes. Why not?”
“No reason; only it’s not our way.”
“Whose way?”
“The way we English people do.”
“Oh, what a Britisher you are!” she said, with a momentary
impatience that led her to forget her self-imposed rôle as hireling.
His lips straightened.
“Certainly. Why not?” he asked quietly.
Baffled, she attempted another line of attack.
“But you were never introduced to me,” she told him.
“Oh, no.”
“And you talk to me.”
“Yes. But that is different.”
“How different?” she demanded.
“You are my nurse.”
Her color came hotly.
“I wasn’t at first.”
Too late she repented her rashness, as Mr. Cecil Barth made
languid answer,—
“No. Still, if I remember clearly, it was you who first spoke to me.
Oh,—nurse!”
But the door banged sharply, and Barth found himself alone with
his ankle and with his thoughts.
“Where is the nurse?” he asked Dr. Howard, a long hour later.
“She went out for a walk.”
“Again?”
“Yes. Have you needed her?”
“Not exactly; but—” Barth hesitated. Then, like the honest
Englishman he was, he went straight to the point. “The fact is,
doctor, I am afraid I said something that vexed her. I didn’t mean to;
I really had no idea of annoying her. I should dislike to hurt her
feelings, for she has been very good to me.”
For the first time in their acquaintance, Dr. Howard could confess
to a liking for his patient. Nevertheless, he only nodded curtly, as he
said,—
“You couldn’t have had a better or more loyal nurse.”
According to her custom, Nancy remained on duty, that evening,
until nine o’clock. Then she moved softly up and down, setting the
room in order for the night. Barth had been lying quiet, staring idly
up at the mammoth shadow of Madame Gagnier, rocking to and fro
just outside the door. Then, as Nancy paused beside him, he turned
to face her.
“Can I do anything more, sir?” she asked, with the gentle
seriousness which marked her moods now and then.
“Nothing, thank you. I am quite comfortable.”
“I am glad. I hope you may have a quiet night.”
“Thank you. I hope I may. You have been very good to me,
nurse, and—” his speech hurried itself a little; “I appreciate it. As I
understand, your wa—salary is paid through the doctor; but perhaps
some little thing that—”
His gesture was too swift and sure to be avoided. The next
instant, Nancy Howard found herself stalking out of the room with
blazing cheeks and with a shining golden guinea clasped in the hot
palm of her left hand.
CHAPTER FIVE
At her window looking out upon the Ring in the ancient Place
d’Armes and upon the Chateau beyond, Nancy Howard stood idly
drumming on the pane. Under its gray October sky, the gray-walled
city of Quebec had appeared most alluring to her, that morning; but
she had turned her back upon its invitation and had resolutely
busied herself in settling her own possessions and those of her
father in the rooms which had been waiting for them at The Maple
Leaf.
Nancy had left Sainte Anne-de-Beaupré with scant regret, the
night before. She had spent numberless interesting hours in the
society of Mr. Cecil Barth. He had piqued her, antagonized her and
occasionally had even compelled her to like him in spite of herself.
However, the whole episode had been forced upon her. Now that it
was ended, she was glad to dismiss it entirely into the past, and she
had not thought it necessary to inform Barth that she too expected
to pass some weeks in Quebec. There was scant chance of their
meeting again, and Nancy had imagined that she had parted from
him without regret.
On his side, Barth had been at no pains to conceal his regrets. As
Dr. Howard had reminded him, Nancy had been a most loyal nurse;
and the young Englishman took it quite as a matter of course that
his attendant should be a girl of brains and breeding as well. He had
heard much of the American college girl, and he promptly
pigeonholed Nancy with others of that class, although in fact she
had been educated by her father and polished by a year or so spent
at a famous old school on the Hudson. Barth admired Nancy’s
brains, her common sense and her alert deftness. To his mind, these
qualities in part atoned for her independence and her hot-headed
Americanism; but only in part. Her society was often restful, but
never cloying; and Barth, now able to hobble about his room, peered
mournfully out of his window after his departing nurse with feelings
akin to those of a youngster suddenly deprived of his best
mechanical toy. Bereft of his nurse, he took to his pipe, smoked
himself into lethargy, and emerged from his lethargy so cross that
Madame Gagnier, lumbering into the room to settle him for the
night, fled from his presence with her cap awry and her checked
pinafore pressed to her aged eyes.
Dusk had fallen, when Nancy and her father drove up the steep
slope of Palace Hill, passed the Basilica and stopped at the low
yellow door of The Maple Leaf. Of the city Nancy saw but little. Of
The Maple Leaf, glaring with electric lights, she saw much and, even
at the first glance, she assured herself that that much was wholly to
her liking. It was not alone the curved ceiling of the entrance
hallway, nor the cheery little dining-room where the four tables and
the huge mahogany sideboard struggled not to elbow each other in
their close quarters; nor yet the deep window-seats of the rooms
with their French casements and their panelled shutters. It was the
nameless flavor of the place, pervading all things and beautifying all
things, the flavor of nothing in the world but of old Quebec. The
Chateau might exist anywhere; The Maple Leaf could have existed
nowhere outside of the ancient city wall.
“Don’t you love it, daddy?” Nancy urged for the third time, as
they came up from their late supper.
“It seems very central,” the doctor assented tranquilly. “Of
course, it is a great advantage for me to be so near Laval. I only
hope you won’t be lonely here, Nancy.”
She laughed scornfully.
“Lonely! After Sainte Anne-de-Beaupré!” she protested.
“The town is often a good deal more lonely than the country,” he
assured her.
But Nancy, whose eyes had not been entirely busy with the
furniture of the dining-room, shook her head. Then she went into
her own room, to fall asleep and, quite as a matter of course, to
dream that Mr. Cecil Barth, Union Jack in hand, was chasing her
around and around the little fountain she could hear plashing down
in the Ring.
All the next morning, Nancy was busy in their two adjoining
rooms, hanging up her gowns and trying to devise an arrangement
which should keep her father’s shirts from too close connection with
his bottle of ink. Now and then she halted beside his windows which
looked down on a gray-walled courtyard where an aged habitant sat
on a chopping-block and peeled potatoes without end. Occasionally
she wandered back to her own room, and stood gazing out at the
Champlain statue by the northern end of the terrace and at the
pointed copper roofs of the huge Chateau. Then she went on
brushing her father’s clothes, and sorting out her own tangle of
gloves and belts and the kindred trifles that add a touch of chaos to
even the most orderly of trunks. At last, her work done, she
smoothed her hair, tweaked her gown into position and, without a
glance into the long mirror of her wardrobe, she ran down to the
dining-room in search of her father.
She found him the sole occupant of a table near the door, and
the other tables were absolutely deserted. As she went back to her
room, Nancy was forced to admit that the meal had been a bit dull.
A father and daughter who have been constant companions for
years, are unable to produce an unfailing stream of brilliant table
talk; and Dr. Howard, tired with the effort of getting his bearings in a
strange library, was even more taciturn than was his wont.
Accordingly, it was in a mood dangerously akin to homesickness that
Nancy left the empty dining-room and returned to her equally empty
bedroom. Once inside the door, she made the mortifying discovery
that her lashes were wet; and, with a swift realization of the
ignominy of her mood, she caught up her hat and coat, and started
out to explore the city on her own account.
As she dressed herself for supper, two nights later, Nancy
confessed to herself that the past two days were the dreariest days
she had ever spent. Totally engrossed in his historical research, her
father spent his daytime hours in poring over the manuscripts in
Laval library, his evening in rearranging and copying his hurried
notes. Left entirely to herself, Nancy discovered the truth of his
words, that a town could be far more lonely than the country. At
Sainte Anne-de-Beaupré, every one had had a word of greeting for
the bright-faced American girl; here it seemed to her that she had
no more personality than one of the pawns on a chessboard. She
walked the streets by the hour at a time, straying at random from
church to church, loitering on the terrace, or tramping swiftly out the
Grand Allée far past the Franciscan convent and the tollgate beyond.
The tourist season was almost ended. A few honeymoon couples
were still straying blissfully about the ramparts; but, for the most
part, Quebec had come back from summer quarters on lake and
river, and was settling into winter routine. Nancy watched it all with
wide, interested, dissatisfied eyes. The show delighted her; but, as
at all other shows, she felt the need of some companion whose
elbow she could joggle in moments of extreme excitement.
As a part of the show, The Maple Leaf had gratified her whole
artistic sense. Humanly speaking, she had found it a bit
disappointing. Manœuvre as she would, she could never succeed in
finding the dining-room full. There seemed to be something utterly
inconsequent in the way in which the boarders took their meals, now
late, now early, and now apparently not at all. She had been told
that there were forty of them; but, so far as she could discover, six
constituted a quorum, and the meal was served accordingly. Once
only, the entire quorum had occurred at her own table. Four fresh-
faced elderly Frenchmen had marched into the room in procession,
and had planted themselves opposite Nancy and her father. Dr.
Howard read French, but spoke it not at all. Nancy felt that her own
three words would prove inadequate. Accordingly, after one
international deadlock over the possession of the salt, silence had
fallen. When she left the table, Nancy felt that she had gained a full
perception of the viewpoint of a deaf mute.
It was with a spirit of absolute desperation that Nancy flung open
the door of her wardrobe, that night. Humanity failing, she would
take refuge in clothes. At Sainte Anne, she had lived chiefly in a
short skirt and blouse; at The Maple Leaf, she had been waiting to
discover the prevailing habits of dress. Now she told herself that two
women at a time could not make a habit; and, furthermore, she
assured herself that she cared nothing for local habits anyway. The
wardrobe held three new gowns, obviously of New York
manufacture. Nancy did not hesitate. With unerring instinct, she
chose the most ornate one of the three, which also chanced to be
the one which was most becoming.
And so it came to pass that Reginald Brock, pausing in the hall to
take off his overcoat, whistled softly to himself as he caught a
glimpse of a pale gown of dusky blue and a head capped with heavy
coils of tawny hair. The coat slid off in a hurry, Brock gave one
hurried look into the tiny mirror of the rack; then, his honest
Canadian face beaming with content, he came striding into the
dining-room and dropped into his place at Nancy’s side, with a
friendly nod of greeting.
CHAPTER SIX
Half an hour later, Brock followed Nancy into the parlor. The Lady
of The Maple Leaf was at his side, and Nancy had an instinctive
feeling that they were in search of her. It was the Lady who spoke.
“Mr. Brock has just been talking to your father in the hall,” she
said; “and now he has asked me to give him a ceremonious
introduction to you. As a rule, we aren’t so ceremonious, here in
Canada; but Mr. Brock insists upon it that the butter-knife and the
mustard are no proper basis for acquaintance.”
“I have learned a thing or two from Johnny Bull,” the tall
Canadian added, as he placed himself in the window-seat beside
Nancy’s chair.
“Johnny Bull?”
“Yes, an English fellow that has been stopping here for a few
days. Where is he? I haven’t seen him for a week,” he added,
turning to the Lady.
“He is ill; I expect him back in a day or two. Please excuse me. I
hear the telephone.” And she hurried out of the room.
Nancy looked after her regretfully. Even during the three days
she had been there, she had gained a sound liking for the blithe little
woman, always busy, never hurried, and invariably at leisure for a
friendly word with any or all of her great family of boarders. Brock’s
glance followed that of Nancy.
“Yes, she is a remarkable woman,” he assented gravely to her
unspoken words. For an instant, his keen gray eyes met Nancy’s
eyes, steadily, yet with no look of boldness. Then his tone changed.
“But about Johnny Bull. He is a revelation to the house, the son of a
stiff-backed generation. He was here for a week, and left us all
trying to get his accent and to imitate his manners.”
“And what became of him?”
“Gone. The Lady says he is ill. I hope we didn’t make him so.
Have you been here long, Miss Howard?”
“Three days.”
“And have you seen anything at all of Quebec?”
“Yes, a little. I have been to the Cathedral, and the Basilica, and
the Gray Nunnery, and the Ursuline Convent, and—”
“You appear to be of an ecclesiastical turn of mind,” Brock
suggested, laughing.
“So does Quebec,” she retorted.
He laughed again.
“Yes, I suppose it does to a stranger; but wait till you have been
here a little longer.”
“What then?”
“You’ll forget that a church exists, except the one you go to, on
Sundays.”
She laughed in her turn.
“Not unless I grow deaf. The Ursuline bell begins to ring at four,
and the one on the Basilica at half-past. From that time on until
midnight, the bells never stop for one single instant. Under such
circumstances, how can one forget that a church exists?”
He modified his statement.
“I mean that you’ll find that Quebec has its worldly side.”
“Which side?” she queried. “As far as I can discover, the city is
bounded on the north by the Gray Nuns, and on the south by the
Franciscan sisters. Moreover, I met Friar Tuck in the flesh, down in
Saint Sauveur, yesterday.”
Brock raised his brows questioningly.
“Do you mean that your explorations have even extended into
Saint Sauveur?”
“Yes. Still, there is hope for me. I haven’t been to the Citadel yet,
and I keep my guide-book strictly out of sight.”
“Out of mind, too, I hope,” he advised her. “It holds one error to
every two facts, and the average tourist carries away the impression
that Montgomery was shot in mid-air, like a hawk above a hen-roost.
If you don’t believe me, go and listen to their comments upon his
tablet.”
“Where is it?”
“Two thirds of the way up Cape Diamond, above Little Champlain
Street. It is labelled as being the spot where Montgomery fell; but,
as it is two hundred feet above the road, one can only infer that he
came down from somewhere aloft. Is this your first visit to Quebec,
Miss Howard?”
“Yes. I have been in Sainte Anne-de-Beaupré for three weeks,
though.”
“Any pilgrimages?” Brock inquired, as he deliberately settled
himself in a less tentative position and crossed his legs. A closer
inspection of Nancy was undermining his vigorous objection to red
hair, and he suddenly determined that the parlor was a much more
attractive spot than he had been wont to suppose.
“One; but it was a large one.”
“Miracles, too?”
Nancy laughed.
“One and a half,” she responded unexpectedly.
“Meaning?” Brock questioned.
“The half miracle was a man who threw away his crutches and
crawled off without them.”
“And the whole one?”
Nancy laughed again. Then she said demurely,—
“That the Good Sainte Anne answered my prayer for a little
excitement.”
“Was that a miracle?”
She answered question with question.
“Did you ever stop at Sainte Anne?”
“Yes, once for the space of two hours. We had all the excitement
I cared for, though.”
Nancy sat up alertly.
“Was it a pilgrimage?”
“No; merely a pig on the track.”
She nestled back again in the depths of her chair.
“What anticlimax!” she protested.
“But you haven’t told me what form your own excitement took,”
Brock reminded her.
“It was an Englishman.”
“Oh, we’re used to those things,” he answered.
“Then I pity you,” she said, with an explosiveness of which she
was swift to repent. “Oh, I beg your pardon,” she added contritely.
“Perhaps you are one of them, yourself.”
“No; merely a Canadian,” Brock reassured her.
“Isn’t it the same thing?”
A mocking light came into Brock’s gray eyes.
“Not always,” he replied quietly.
“No.” Nancy’s tone was thoughtful. “I am beginning to find it out.
Our Englishman was unique.”
“Ours?”
“Yes, by adoption. The Good Sainte Anne and I took him in
charge.”
“With what success?”
“It remains to be seen. We did our best for him; but really he
was very preposterous.”
“What became of him?”
“Nothing.”
“Nothing?”
“No. He is there now; at least, he was there, when we came
away.”
“Was he working out his novena?”
“No; just mending himself. He fell off from something, his dignity
most likely, and bumped his head and sprained his ankle. I
happened to be on the spot, and rashly admitted that my father was
a doctor. Then, before I really had grasped the situation, the poor
man was bundled into a cart and deposited at our door, half fainting
and wholly out of temper.”
“And then?”
“And then we couldn’t get a nurse for love or money, and I had
to go to work and take care of him.”
“Happy man!” Brock observed. “I only hope he appreciated his
luck.”
The corners of Nancy’s mouth curved upwards, and a malicious
light came into her eyes.
“I think he did. He not only expressed himself as pleased with my
services; but, on one occasion, he gave me a—”
“A what?”
“A brand-new guinea.” And Nancy’s laugh rang out so infectiously
that Brock would have joined in it, if she had been discussing the
foibles of himself rather than of the unknown Englishman.
“How exactly like our Johnny Bull!” he commented, when he
found his voice once more.
Suddenly Nancy’s puritan conscience asserted itself.
“Truly, I ought not to laugh about him, Mr. Brock. He had no idea
that I was anything but a servant, and he thought he had every
reason to tip me. He wasn’t bad, only very funny. He really knew a
great deal and, according to his notions, he was a most perfect
gentleman. It was only that our notions clashed sometimes. Yes,
daddy, I am coming. Good night, Mr. Brock.” And she left him staring
rather wishfully after the disappearing train of her dull blue gown.
It must be confessed that Brock dawdled over his breakfast, the
next morning; but his dawdling was quite in vain. Nancy had taken
her own breakfast long before he appeared, and, by the time Brock
had reached his second cup of coffee, she was walking rapidly along
the terrace towards the Citadel. At the end, she paused for a
moment of indecision. Then, with a glance up at the Union Jack
above her head, she slowly mounted the long flight of steps and
came out on the narrow upper terrace which skirts the outer wall of
the fortress. There she paused again and stood, her arms folded on
the railing, looking down on the picture at her feet. She had been
there once before; to-day, however, the impression was keener,
more enjoyable. The change might have come from the sunshine
that lay in yellow splashes over the city beneath; it might have come
in part from the memory of her idle talk with Brock, the night before.
In all that town of antiquity and of strangers, it had been good to
meet some one whose age and viewpoint corresponded to her own.
The direct gaze of Brock’s clear eyes had pleased Nancy. She had
liked his voice, and the unconscious ease with which he carried his
seventy-three inches of height. Too outward seeming, his type was
as unfamiliar as that of the Englishman, and Nancy liked it vastly
better. With Barth, she had been standing on tiptoe, psychologically
speaking. With Brock, she could be her every-day, normal self.
It had been at Brock’s suggestion that she had gone to the upper
terrace, that morning; and she shook off the memory of his gray
eyes in order to recall the dozen sentences with which he had
characterized the salient points of the view beneath. Then she gave
up the attempt. In the face of all that beauty, it was impossible to fix
one’s mind upon mere questions of geography. At her left, the city
sloped down to Saint Roch and the Charles River beyond, and
beyond that again was the long white village of Beauport straggling
along the bluff above the river. At her right, quarter of a mile beyond
the Citadel, were the ruined hillocks of the old French fortifications;
and, on the opposite shore, the town of Lévis was crested with its
trio of forts and dotted with tapering spires of gray. From one of the
piers below, a little steamer was swinging out into midstream and
heading towards the point where Sillery church overlooks the valley;
and, close against the base of the cliff, the irregular roofs of
Champlain Street lay huddled in a long line of shadow. The river was
shadowy, too; but above the city a rift in the clouds sent the strong
sun pouring down over the guns on the eastern ramparts, over the
southern tower of the Basilica and over the spires of Laval. As she
looked, Nancy drew a long breath of sheer delight and, all at once
and for no assignable cause, she decided that she was glad she had
come. Then abruptly she turned her back upon a tall figure crossing
Dufferin Terrace, and walked swiftly away past Cape Diamond and
came out on the Cove Fields beyond.
When she came in to dinner, she was flushed and animated. As
Brock had predicted, she had discovered that Quebec’s interest did
not centre wholly in its churches. True, there had been a certain
disillusion in finding a portly Englishman playing golf with himself
upon the ground over which the French troops had marched out to
face the invading, conquering foe, in seeing a Martello Tower begirt
with clothes-lines and flapping garments, and in discovering a brand-
new rifle factory risen up, Phœnix-like, from the ashes of the old-
time battleground. The impression was blurred a little; nevertheless,
it was there, and Nancy, as her feet wandered up and down the trail
of the armies upon that thirteenth of September of the brave year
’Fifty-nine, took a curious satisfaction in the fact that Wolfe, too, had
been banned with a head of red hair. Her own ancestors were
English. Perhaps some of their kin had landed at Sillery Cove, to
scale the cliff and die like gentlemen upon the Plains of Abraham.
Her blood flowed more quickly at the thought. In Nancy’s mind, this
was the hour of England. She even forgot the shining golden guinea
that reposed among her extra hairpins.
Nancy came into the house to find the Lady packing a dinner into
an elaborate system of pails and cosies. The Lady looked up with a
smile.
“Our invalid has come back again,” she explained; “and I am
sending his dinner over to his room.”
CHAPTER SEVEN
“Well,” Brock inquired, three days later; “have you been doing
ecclesiastics again, to-day?”
Nancy, glancing up from her soup, registered the impression that
Brock supported an extremely good tailor, and that his Sabbath
raiment was becoming to him.
“Yes. You told me that this was the proper day for it.”
“Where did you go?”
“To the Basilica, of course.”
Brock smiled.
“True to the tradition of the tourist. By the way, that’s rather a
good alliteration. I think I’ll use it again sometime.”
Nancy disregarded his rhetorical outburst and pinned her
attention to the fact.
“Do they always go there?”
“Yes, to start with. Of course, you didn’t stop there.”
“But I did. Why not?”
“Miss Howard, you have neglected your opportunities. The
regular tourist itinerary begins with the Basilica at ten, sneaks out
and goes over to the English Cathedral at eleven and follows on the
tail of the band when it escorts the soldiers home to the Citadel.
Then it takes in the Ursuline Chapel at two, stops to drop a tear over
Montcalm’s skull and then skurries off, on the chance of getting in an
extra service before five-o’clock Benedictions at the Franciscan
Convent.”
“The white chapel with the pale green pillars?”
“Yes, out on the Grand Allée.”
“I’ve been there,” she assented. “I love the place.”
“And then,” Brock continued inexorably; “if you make good time
over your supper, you can just get back to the Basilica at seven.”
Nancy drew a long breath.
“But I don’t need to do all that,” she objected. “There are more
Sundays coming.”
“That makes no difference. Every stranger is bound to gallop
through his first Sunday in Quebec. It is one of the duties of the
place. You think you won’t do it; but, at two o’clock, you’ll have an
uneasy consciousness that those cloistered nuns over at the Ursuline
may do something or other worth seeing. By quarter past two, you’ll
be buried in a haze of mediævalism and incense.”
“Never!” she protested, with what proved to be strict adherence
to truth.
“And what about the Basilica?” Brock asked her.
“Superb!” Nancy’s eyes lighted. “I was there, a few days ago. It
was empty, and it didn’t impress me in the least. It seemed to me a
dead weight of white enamel paint and gold leaf, so heavy that it
wasn’t even cheerful. But to-day—”
“To-day?” he echoed interrogatively.
But Nancy made an unexpected digression.
“Mr. Brock, what is that huge pinky-purple Tam O’Shanter
dangling above the chancel?”
“Miss Howard, where was your bump of reverence, and where
were your guide-books?”
“My bump of reverence was fastened down with hatpins, and my
guide-books are buried in the bottom of my trunk.”
“Since when?”
“Since I made the discovery that Quebec must be inhaled, not
analyzed,” she responded promptly.
Brock laid down his knife and fork, and patted his hands together
in mock applause.
“A subtle distinction. Might I ask whether it applies to the
incense?”
Nancy made a wry face.
“No. Incense should be a symbol, not a fact. It is destructive to
all my devotional spirit. Still, even in this one week, I have become
an epicure in it. Granted that the wind is in the right direction, I can
recognize the brand at least a block away. I like the kind they use at
the Basilica best. That out at the Franciscan Convent is doubtless
choice; but it is a bit too pungent for my Protestant nose.” Then of a
sudden her face grew grave. “Please don’t think I am making fun of
serious matters, Mr. Brock,” she added. “Even if I do dislike the
incense, I can appreciate the beauty of the service, and I should be
ashamed of myself, if I couldn’t be really and truly reverent in the
midst of all that dignified worship.”
Brock was no Catholic; he possessed the average devoutness of
his age and epoch. Nevertheless, he liked Nancy’s swift change of
mood. All in all, he liked Nancy extremely, and he was sincerely
grateful to the fate which had given him this attractive table
companion. The past three days had brought them into an excellent
understanding and friendship. Trained in totally different lines, they
yet had many a point in common. They were equally direct, equally
frank, equally blest with the saving sense of humor. In spite of the
dainty femininity of all her belongings, Nancy met Brock with the
unconscious simplicity of a growing boy. The manner was new to
Brock, and he found it altogether pleasing. Most of the women he
had met, had contrived to impress upon him that he was expected
to flirt with them. It was obvious that Nancy Howard wished either
to be liked for herself, or to be let alone.
“Then you enjoyed yourself?” he asked.
Nancy’s mind went swiftly backward over the morning.
Impressionable and artistic of temperament, she could yet feel the
thrill which accompanies the worship of close-packed, kneeling
humanity, still hear the chanting of the huge antiphonal choirs, the
throng of priests in the chancel answered by the green-sashed
seminarians in the organ loft above. The gorgeous robes of the
celebrants, the ascetic face of the young preacher, and even the
motley crowd who, too poor to hire seats in a church of such wealth
and fashion, knelt in a huddled mass of humanity upon the bare
pavement just within the nave: all these were details; but they
helped to fill in a picture of absolute devotion and faith. Nancy raised
her eyes to Brock’s face.
“I would be willing to pray with a rosary, all my days,” she said
impulsively; “if it would give me the look of some of those people.”
For a moment, Brock felt, the look was hers. Then she laughed
again.
“Still, I shall always have one regret. Why didn’t you tell me how
to make a procession of myself?”
“What do you mean?”
“About the gorgeous man that ushers one in?”
“I didn’t know there was one.”
“Mr. Brock!”
“Miss Howard?”
“But you ought to.”
“But I don’t go to the Basilica.”
“Not always, of course; but surely sometimes.”
“I was never inside the doors.”
“I met,” Nancy observed reflectively; “a New York man, last
summer, who had never set eyes on the Washington Arch.”
“Well?”
“Well, the two cases seem to me to be about parallel.”
Brock reddened. Nevertheless, it was impossible to take offence
at Nancy’s downright tone and, the color still in his cheeks, he
laughed.
“I may as well plead guilty. But who is the man?”
“The New Yorker?”
“No; the Basilica.”
“What is he, you’d better say. He appears to be a mixture of an
usher, a tithingman and a glorious personification of the Church
Militant. He is at least six feet tall, and he wears a long blue coat
with scarlet facings and yards of gold lace. That would be impressive
enough; but he gains an added bit of dignity by perambulating
himself up the aisles with a tall, gold-headed sceptre in his hand.”
“Did he also perambulate you?”
Nancy’s head moved to and fro in sorrowful negation.
“No; nobody told me about him, and I lost my chance. I was so
disappointed, too. One doesn’t get a chance, every day in the week,
to be converted into a whole triumphal procession with an
ecclesiastical drum-major at its head.”
“Most likely it is only a Sunday luxury there,” Brock suggested
dryly. “But what did you do?”
Nancy’s face lengthened.
“I disgraced myself,” she confessed. “But how could I know the
customs of the country? I went in good season, and I stood back,
meekly waiting for an usher, until the whole open space around me
was full of men, kneeling on handkerchiefs and newspapers and
even on their soft hats. I began to feel like a Tower of Babel set out
in the middle of a village of huts. I know I never was half so tall
before. And still no usher came. At last, I couldn’t bear it any longer,
and I sneaked into an empty pew, half-way up the aisle.”
Brock nodded.
“Oh; but it wasn’t at all the right thing to do. I was barely seated,
when I felt a forefinger poke itself into my shoulder. I looked around,
and there stood a woman in crape, frowning at me as if I were a
naughty child. She whispered something to me. It sounded very
stern; but I couldn’t understand what it was about, so I just smiled
at her and started to move in. But she poked me again, quite
viciously, that time, and pointed out into the aisle. Then I
understood her.”
“And obeyed?” Brock asked, laughing.
“What else could I do? She was taller than I.”
“And then?”
“Then the Good Samaritan appeared.”
“The gold-laced one?”
“No; nothing so impressive. He was a little Frenchman who came
out of his pew farther down the aisle, and in the nicest possible
English asked me to go there with him. You’ve no idea how merciful
he was to me, nor how I appreciated it. I was beginning to feel like
an outcast, and he saved my self-respect and returned it to me,
unbroken.”
Brock started to answer; but Dr. Howard had appealed to Nancy
for confirmation of one of his statements. By dint of much effort and
at cost of frequent misunderstandings, the good doctor had
established relations with his neighbor across the table, and the two
men had been toiling through a prolonged conversation. Concerning
mere matters of theory, each fondly imagined that he understood
the other perfectly. Confronted with the problem of the ultimate
destination of the sugar-bowl, they lost their bearings completely,
and were forced to supplement their tongues with the use of their
right forefingers.
Nancy’s acquaintance with the row of Frenchmen was limited to
the careful distribution, at every meal, of exactly two little nods
apiece, one of hail, the other of farewell. Since her first meeting with
Brock, she had been surprised at the chance which had continually
brought them into the dining-room at the same hour; and, in her
absorption in his talk, one or other of the Frenchmen was often half
through his deliberate meal before she remembered to deal out to
him his nod of greeting. She liked them well enough; but, at the
present stage of intercourse, they seemed to her a good deal like
well-bred automatons.
While Nancy talked to her father, Brock eyed her furtively. She
wore a dark green gown, that noon, and her vivid hair was piled
high in an intricate heap of burnished coils. Her hands were bare of
rings, her whole costume void of the dangling ornaments which
Brock so keenly detested; but, close in the hollow of her throat,
there blazed one great opal like a drop of liquid fire.
So suddenly that he had no time to drop his eyes to his plate,
Nancy turned to him.
“Mr. Brock, there is my French Samaritan!” she exclaimed softly.
Brock glanced up at the figure who was moving past the table
where they sat.
“That? That is St. Jacques,” he said.
“Who is he?”
“A law student, over at Laval, and one of the best fellows walking
the earth at the present time,” Brock answered, with the swift
enthusiasm which, as Nancy discovered in the weeks to come, was
one of his most striking characteristics.
Nancy rested her elbows on the table, with a fine disregard of
appearances.
“Well, he looks it,” she said impressively.
“He’s all right.” Brock nodded over his grapes.
“And lives here?”
“Eats here; that’s all. The table just back of you is full of Laval
men. They come in relays, twenty of them for the six seats; and
Johnny Bull sits enthroned among them like a mute at the funeral
feast. St. Jacques sits just back of your father. I wonder you haven’t
noticed him before.”
Nancy played aimlessly with her grapes for a minute or two.
Then, turning slightly in her chair, she looked over her shoulder
towards the next table. As she did so, the man who sat exactly at
her back, moved by some sudden impulse, turned at the same
instant, and Nancy found herself staring directly into the
unrecognizing eyeglasses of no less a person than Mr. Cecil Barth.
CHAPTER EIGHT
To adopt the vernacular of the stables, Nancy shied violently, for
the apparition was both unexpected and unwelcome. She rallied
swiftly, however, and, promptly resolving to make the best of a bad
matter, she gave a little nod and smile of recognition. The next
instant, both nod and smile went sliding away from the unresponsive
countenance of Mr. Cecil Barth and focussed themselves with an
added touch of cordiality upon M. St. Jacques, while the young
Frenchman bowed low in surprised pleasure at her friendly greeting.
Even in her instantaneous glance, Nancy saw that Barth looked
worn and ill; and, with unregenerate spite working in her heart, she
told herself that she was glad of it. She had no idea that, unable to
supply himself with new glasses before his return to the city, Barth
had gained absolutely no conception of the personal appearance of
his quondam nurse. Moreover, as Nancy had neglected to inform him
in regard to her normal pursuits and her future plans, he had spent
the last week in regretfully picturing her, still in cap and pinafore,
ministering to the needs of some invalid Yankee in that vast
unknown which he vaguely termed The States. Accordingly, it came
about that the dinner, that Sunday noon, was finished in hot rage by
Nancy, in joyous anticipation by Adolphe St. Jacques, and in stolid
unconcern by Mr. Cecil Barth who was aware neither of the existence
of an emotional crisis, nor of the fact that to him was due any share
of its creation.
Nancy sat alone in the parlor, after dinner, waiting for her father
to join her, when Barth came into the room. He halted on the
threshold long enough to look her over in detail; then he limped past
her and took possession of the chair beyond her own. As they sat
there silent, elbow to elbow, Nancy was conscious of a wayward
longing to remind him that it was high time for his liniment.
However, she refrained. Two could play at that game of stolid
disregard.
The Lady looked puzzled, as she followed Barth into the room, a
few moments later. Only a day or two before, Nancy, moved by a
spirit of iniquity, had confided to the Lady the whole tale of her
connection with Barth, and the Lady, who already adored Nancy and,
moreover, was discerning enough to see the inherent manliness of
Barth, had held her peace. A charming scene of recognition was
bound to follow Barth’s return to The Maple Leaf. No hint of a
mystery to come should take from the glamor of that pleasant
surprise. Barth and Nancy both were curiously alone; both were
aliens, meeting upon neutral soil. Already in her mind’s eye the Lady
foresaw romance and international complications.
With her bodily eye the Lady saw the elements of her
international complications sitting in close juxtaposition, but with
their backs discreetly turned to an obtuse angle with each other. She
made a swift, but futile, effort to account for the situation. Then she
gave Nancy a merry nod of comprehension, if not of understanding,
and passed on to speak to Barth.
“You are better, to-day, I hope.”
“Oh, yes.”
“I hope you didn’t feel obliged to come over to dinner. It was no
trouble to send your meals to you.”
“Oh, no. I was tired of stopping in my room.”
“You look as if you had been having rather a hard time of it,” the
Lady said kindly.
“Yes. I never supposed an ankle could be so painful. Still, I hope
it is over now.”
“Then it doesn’t trouble you to walk?”
“Oh, rather! And, besides, it makes one such an object, you
know, and then people stare. It won’t be long, though, I dare say,
before I can walk without limping.”
A naughty impulse seized upon the Lady.
“You were at Sainte Anne-de-Beaupré, you said? And could you
get proper care in so small a place?”
Over the unconscious head of Mr. Cecil Barth, Nancy shook her
fist at the Lady. Then she fled from the room; but not quickly
enough to lose Barth’s answer,—
“Oh, so-so; nothing extra, but still quite tolerable. The doctor
was clever; but the nurse, his daughter, was an American, a good-
hearted sort of girl, but rather rude and untrained.”
All that Sunday afternoon, Nancy cherished her hopes of
vengeance. Plan after plan suggested itself to her fertile brain, was
weighed and found wanting. Planned hostility was totally
inadequate; she would leave everything to chance. Nevertheless,
Nancy tarried long at her mirror, that night; and she went down to
supper with her head held high and a brilliant spot of color in either
cheek. As she passed the parlor door, she saw Barth, book in hand,
seated exactly where she had left him, and she suddenly realized
that, rather than endure the short walk to his room, he had chosen
to spend his afternoon in the dreary solitude of a public sitting-room.
For an instant, her heart smote her, and her step lagged a little; then
she remembered the guinea, and recalled Barth’s words, that noon,
and her step quickened once more.
Brock followed her back to the parlor.
“Oh, let the Basilica go, to-night,” he urged.
“But you told me it was a part of my itinerary.”
“No matter. You haven’t kept up your round, to-day, anyway. Did
you do the Ursulines, this afternoon?”
“No. I was all ready to go; but something happened that put me
in an unchurchly frame of mind,” Nancy said vindictively.
“Just as well. It makes people suspicious of your past habits, if
you rush too violently into church-going.”
“But twice isn’t too violently.”
“Two is too,” he retorted. “Besides, St. Jacques asked me to ask
you if he might be formally introduced, to-night.”
Nancy’s face brightened, and her voice lost the little sharp edge it
had taken on with her reference to her encounter with Barth.
“Of course. Both on account of his courtesy to me, and of your
characterization of him, I shall be delighted to meet him. Where is
he?”
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookluna.com

You might also like