Introduction to Computing Systems From bits and
gates to C and beyond 2nd International Edition
Yale Patt pdf download
https://ebookfinal.com/download/introduction-to-computing-
systems-from-bits-and-gates-to-c-and-beyond-2nd-international-
edition-yale-patt/
Explore and download more ebooks or textbooks
at ebookfinal.com
We have selected some products that you may be interested in
Click the link to download now or visit ebookfinal.com
for more options!.
From Kosovo to Kabul and Beyond Human Rights and
International Intervention David Chandler
https://ebookfinal.com/download/from-kosovo-to-kabul-and-beyond-human-
rights-and-international-intervention-david-chandler/
Introduction to Grid Computing 1st Edition Frederic
Magoules
https://ebookfinal.com/download/introduction-to-grid-computing-1st-
edition-frederic-magoules/
Database Systems Introduction to Databases and Data
Warehouses 2nd Edition Nenad Jukic■
https://ebookfinal.com/download/database-systems-introduction-to-
databases-and-data-warehouses-2nd-edition-nenad-jukic/
Introduction to Optical Microscopy 2nd Edition Jerome C.
Mertz
https://ebookfinal.com/download/introduction-to-optical-
microscopy-2nd-edition-jerome-c-mertz/
Practicing Harm Reduction Psychotherapy An Alternative
Approach to Addictions 2nd Edition Patt Denning
https://ebookfinal.com/download/practicing-harm-reduction-
psychotherapy-an-alternative-approach-to-addictions-2nd-edition-patt-
denning/
Introduction to Building Procurement Systems 2nd Edition
Dr Jack Masterman
https://ebookfinal.com/download/introduction-to-building-procurement-
systems-2nd-edition-dr-jack-masterman/
Introduction to High Performance Computing for Scientists
and Engineers 1st Edition Georg Hager
https://ebookfinal.com/download/introduction-to-high-performance-
computing-for-scientists-and-engineers-1st-edition-georg-hager/
Stimuli Responsive Drug Delivery Systems From Introduction
to Application 1st Edition Bajpai
https://ebookfinal.com/download/stimuli-responsive-drug-delivery-
systems-from-introduction-to-application-1st-edition-bajpai/
Structure and Function From clause to discourse and beyond
Christopher Butler
https://ebookfinal.com/download/structure-and-function-from-clause-to-
discourse-and-beyond-christopher-butler/
Introduction to Computing Systems From bits and gates to C and beyond 2nd International Edition Yale Patt
Introduction to Computing Systems From bits and gates
to C and beyond 2nd International Edition Yale Patt
Digital Instant Download
Author(s): Yale Patt, Sanjay Patel
ISBN(s): 9780071245012, 0071245014
Edition: 2nd International
File Details: PDF, 13.10 MB
Year: 2005
Language: english
introduction to
computing systems
The McGraw-Hill Companies
Mc
Graw
Hill
INTRODUCTION TO COMPUTING SYSTEMS: FROM BITS AND GATES TO C AND BEYOND
SECOND EDITION
International Edition 2005
Exclusive rights by McGraw-Hill Education (Asia), for manufacture and export. This book cannot be
re-exported from the country to which it is sold by McGraw-Hill. The International Edition is not
available in North America.
Published by McGraw-Hill, a business unit of The McGraw-Hill Companies, Inc., 1221 Avenue of the
Americas, New York, NY 10020. Copyright © 2004, 2001 by The McGraw-Hill Companies, Inc. All
rights reserved. No part of this publication may be reproduced or distributed in any form or by any
means, or stored in a database or retrieval system, without the prior written consent of The McGraw-
Hill Companies, Inc., including, but not limited to, in any network or other electronic storage or
transmission, or broadcast for distance learning.
Some ancillaries, including electronic and print components, may not be available to customers outside
the United States.
10 09 08 07 06 05 04 03 02 01
20 09 08 07 06 05 04
CTF SEP
Cover images: ©Photodisc, AA048376 Green Abstract, AA003317 Circuit Board Detail
Library of Congress Control Number: 2003051002
When ordering this title, use ISBN 007-124501-4
Printed in Singapore
> > second edition
introduction to
computing systems
from bits and gates to C and beyond
Yale N. Patt
The University of Texas at Austin
Sanjay J. Patel
University of Illinois at Urbana-Champaign
Mc
Graw
Hill
Higher Education
Boston Burr Ridge, IL Dubuque, IA Madison, Wl New York San Francisco St. Louis
Bangkok Bogota Caracas Kuala Lumpur Lisbon London Madrid Mexico City
Milan Montreal New Delhi Santiago Seoul Singapore Sydney Taipei Toronto
To the memory of my parents,
Abraham Walter Patt A"H and Sarah Clara Patt A"H,
who taught me to value "learning"
even before they taught me to ride a bicycle.
To Mira and her grandparents,
Sharda Patel and Jeram Patel.
contents
Preface xi
Preface to the First Edition
1 Welcome Aboard 1
XVII
2.4.1 Binary to Decimal Conversion 27
2.4.2 Decimal to Binary Conversion 28
1.1
1.2
1.3
1.4
1.5
1.6
1.7
What We Will Try to Do 1
How We Will Get There 2
Two Recurring Themes 3
1.3.1 The Notion of Abstraction 3
1.3.2 Hardware versus Software 5
A Computer System 7
Two Very Important Ideas 9
Computers as Universal Computational
Devices 9
How Do We Get the Electrons to Do the
Work?
1.7.1
1.7.2
1.7.3
1.7.4
1.7.5
1.7.6
1.7.7
1.7.8
Exercises 17
12
The Statement of the Problem 13
The Algorithm 13
The Program 14
The ISA 14
The Microarchitecture 15
The Logic Circuit 16
The Devices 16
Putting It Together 16
2 Bits, Data Types, and
Operations 21
2.1
2.2
2.3
2.4
Bits and Data Types 21
2.1.1 The Bit as the Unit of
Information 21
2.1.2 Data Types 22
Integer Data Types 23
2.2.1 Unsigned Integers 23
2.2.2 Signed Integers 23
2's Complement Integers 25
Binary-Decimal ..Conversion 27
2.5 Operations on Bits—Part I: Arithmetic
2.5.1 Addition and Subtraction 29
2.5.2 Sign-Extension 30
2.5.3 Overflow 31
2.6 Operations on Bits—Part I I : Logical
Operations 33
2.6.1 v The AND Function 33
2.6.2 The OR Function 34
2.6.3 The NOT Function 35
2.6.4 The Exclusive-OR Function 35
2.7 Other Representations 36
2.7.1 The Bit Vector 36
2.7.2 Floating Point Data Type 37
2.7.3 ASCII Codes 40
2.7.4 Hexadecimal Notation 41
Exercises 43
3 Digital Logic Structures 51
3.1 The Transistor 5 1
3.2 Logic Gates 53
3.2.1 The NOT Gate (Inverter) 53
3.2.2 OR and NOR Gates 54
3.2.3 AND and NAND Gates 56
3.2.4 DeMorgan's Law 58
3.2.5 Larger Gates 58
3.3 Combinational Logic Circuits 59
3.3.1 Decoder 59
3.3.2 Mux 60
3.3.3 Full Adder 61
3.3.4 The Programmable Logic Array
(PLA) 63
3.3.5 Logical Completeness 64
Basic Storage Elements 64
3.4.1 The R-S Latch 64
3.4.2 The Gated D Latch 66
3.4.3 A Register 66
29
3.4
vi Contents
3.5 The Concept of Memory 67
3.5.1 Address Space 68
3.5.2 Addressability 68
3.5.3 A 22
-by-3-Bit Memory 68
3.6 Sequential Logic Circuits 70
3.6.1 A Simple Example: The Combination
Lock 71
3.6.2 The Concept of State 72
3.6.3 Finite State Machines 74
3.6.4 An Example: The Complete
Implementation of a
Finite State Machine 77
3.7 The Data Path of the LC-3 80
Exercises 82
5.4 Control Instructions 130
5.4.1 Conditional Branches 131
5.4.2 An Example 132
5.4.3 Two Methods for Loop Control 135
5.4.4 Example: Adding a Column of
Numbers Using a Sentinel 135
5.4.5 The JMP Instruction 136
5.4.6 The TRAP Instruction 137
5.5 Another Example: Counting Occurrences of
a Character 138
5.6 The Data Path Revisited 141
5.6.1 Basic Components of the Data
Path 141
5.6.2 The Instruction Cycle 144
Exercises 145
4 The von Neumann Model 97
4.1 Basic Components 97
4.1.1 Memory 98
4.1.2 Processing Unit 99
4.1.3 Input and Output 100
4.1.4 Control Unit 100
4.2 The LC-3: An Example von Neumann
Machine 101
4.3 Instruction Processing 103
4.3.1 The Instruction 103
4.3.2 The Instruction Cycle 104
4.4 Changing the Sequence of Execution 107
4.4.1 Control of the Instruction
Cycle 108
4.5 Stopping the Computer 110
Exercises 111
6 Programming 155
6.1 Problem Solving 155
6.1.1 Systematic Decomposition 155
6.1.2 The Three Constructs: Sequential;
Conditional, Iterative 156
6.1.3 LC-3 Control Instructions to
Implement the Three
Constructs 157
6.1.4 The Character Count Example from
Chapter 5, Revisited 158
6.2 Debugging 162
6.2.1 Debugging Operations 163
6.2.2 Examples: Use of the Interactive
Debugger 164
Exercises 172
5 The LC-3 115
5.1 The ISA: Overview 115
5.1.1 Memory Organization 116
5.1.2 Registers 116
5.1.3 The Instruction Set 117
5.1.4 Opcodes 117
5.1.5 Data Types 118
5.1.6 Addressing Modes 118
5.1.7 Condition Codes 120
5.2 Operate Instructions 120
5.3 Data Movement Instructions 123
5.3.1 PC-Relative Mode 124
5.3.2 Indirect Mode 125
5.3.3 Base+offset Mode 127
5.3.4 Immediate Mode 128
5.3.5 An Example 129
7 Assembly Language 177
7.1 Assembly Language Programming —
Moving Up a Level 177
7.2 An Assembly Language Program 178
7.2.1 Instructions 179
7.2.2 Pseudo-ops (Assembler
Directives) 182
7.2.3 Example: The Character Count
Example of Section 5.5,
Revisited 183
7.3 The Assembly Process 185
7.3.1 Introduction 185
7.3.2 A Two-Pass Process 185
7.3.3 The First Pass: Creating the Symbol
Table 186
7.3.4 The Second Pass: Generating the
Machine Language Program 187
Contents vii
7.4 Beyond the Assembly of a Single Assembly
Language Program 188
7.4.1 The Executable Image 189
7.4.2 More than One Object File 189
Exercises 190
8 I/O 199
8.1 I/O Basics 199
8.1.1 Device Registers 199
8.1.2 Memory-Mapped I/O versus Special
Input/Output Instructions 200
8.1.3 Asynchronous versus
Synchronous 200
8.1.4 Interrupt-Driven versus Polling 202
8.2 Input from the Keyboard 202
8.2.1 Basic Input Registers (the KBDR and
the KBSR) 202
8.2.2 The Basic Input Service
Routine 202
8.2.3 Implementation of Memory-Mapped
Input 203
8.3 Output to the Monitor 204
8.3.1 Basic Output Registers (the DDR and
the DSR) 204
8.3.2 The Basic Output Service
Routine 205
8.3.3 Implementation of Memory-Mapped
Output 206
8.3.4 Example: Keyboard Echo 207
8.4 A More Sophisticated Input Routine 207
8.5 Interrupt-Driven I/O 209
8.5.1 What Is Interrupt-Driven I/O? 209
8.5.2 Why Have Interrupt-Driven
I/O? 210
8.5.3 Generation of the Interrupt
Signal 211
8.6 Implementation of Memory-Mapped 1/0/
Revisited 214
Exercises 215
9.1.5 TRAP Routines for Handling
I/O 225
9.1.6 TRAP Routine for Halting the
Computer 225
9.1.7 Saving and Restoring
Registers 229
9.2 Subroutines 230
9.2.1 The Call/Return Mechanism 230
9.2.2 The JSR(R) Instruction 232
9.2.3 The TRAP Routine for Character
Input, Revisited 233
9.2.4 PUTS: Writing a Character String to
the Monitor 235
9.2.5 Library Routines 235
Exercises 240
10 And, Finally . . . The Stack 251
10.1 The Stack: Its Basic Structure 251
10.1.1 The S t a c k - A n Abstract Data
Type 251
10.1.2 Two Example Implementations 252
10.1.3 Implementation in Memory 253
10.1.4 The Complete Picture 257
10.2 Interrupt-Driven I/O (Part 2) 258
10.2.1 Initiate and Service the
Interrupt 259
10.2.2 Return from the Interrupt 261
10.2.3 An Example 262
10.3 Arithmetic Using a Stack 264
10.3.1 The Stack as Temporary
Storage 264
10.3.2 An Example 265
10.3.3 OpAdd, Op Mult, and OpNeg 265
10.4 Data Type Conversion 272
10.4.1 Example: The Bogus Program:
2 + 3 = e 272
10.4.2 ASCII to Binary 273
10.4.3 Binary to ASCII 276
10.5 Our Final Example: The Calculator 278
Exercises 283
9 TRAP Routines and
Subroutines 219
9.1 LC-3 TRAP Routines 219
9.1.1 Introduction 219
9.1.2 The TRAP Mechanism 220
9.1.3 The TRAP Instruction 221
9.1.4 The Complete Mechanism 222
11 Introduction to Programming
inC 289
11.1 Our Objective 289
11.2 Bridging the Gap 290
11.3 Translating High-Level Language
Programs 292
viii Contents
11.3.1 Interpretation 292
11.3.2 Compilation 293
11.3.3 Pros and Cons 293
11.4 The C Programming Language 293
11.4.1 The C Compiler 295
11.5 A Simple Example 297
11.5.1 The Function m a i n 297
11.5.2 Formatting, Comments, and
Style 299
11.5.3 The C Preprocessor 300
11.5.4 Input and Output 3 0 1
11.6 Summary 3 0 4
Exercises 3 0 5
12 Variables and Operators 307
1 2 . 1 Introduction 3 0 7
12.2 Variables 3 0 8
12.2.1 Three Basic Data Types: int, char,
d o u b l e 308
12.2.2 Choosing Identifiers 310
12.2.3 Scope: Local versus Global 3 1 1
12.2.4 More Examples 313
12.3 Operators 3 1 4
12.3.1 Expressions and Statements 315
12.3.2 The Assignment Operator 316
12.3.3 Arithmetic Operators 317
12.3.4 Order of Evaluation 318
12.3.5 Bitwise Operators 319
12.3.6 Relational Operators 320
12.3.7 Logical Operators 322
12.3.8 Increment/Decrement
Operators 322
12.3.9 Expressions with Multiple
Operators 324
12.4 Problem Solving Using Operators 3 2 4
12.5 Tying it All Together 3 2 6
12.5.1 Symbol Table 326
12.5.2 Allocating Space for Variables 328
12.5.3 A Comprehensive Example 331
12.6 Additional Topics 332
12.6.1 Variations of the Three Basic
Types 332
12.6.2 Literals, Constants, and Symbolic
Values 334
12.6.3 Storage Class 335
12.6.4 Additional C Operators 336
12.7 Summary 337
Exercises 3 3 8
13 Control Structures 343
1 3 . 1 Introduction 3 4 3
13.2 Conditional Constructs 3 4 4
13.2.1 The if Statement 344
13.2.2 The if-else Statement 347
13.3 Iteration Constructs 3 5 0
13.3.1 The while Statement 350
13.3.2 The for Statement 353
13.3.3 The do-while Statement 358
13.4 Problem Solving Using Control
Structures 3 5 9
13.4.1 Problem 1: Approximating the Value
of 7i 360
13.4.2 Problem 2: Finding Prime Numbers
Less than 100 362
13.4.3 Problem 3: Analyzing an E-mail
Address 366
13.5 Additional C Control Structures 3 6 8
13.5.1 The switch Statement 368
13.5.2 The break and continue
Statements 370
13.5.3 An Example: Simple
Calculator 370
13.6 Summary 372
Exercises 372
14 Functions 379
1 4 . 1 Introduction 3 7 9
14.2 Functions in C 3 8 0
14.2.1 A Function with a Parameter 380
14.2.2 Example: Area of a Ring 384
14.3 Implementing Functions in C 3 8 5
14.3.1 Run-Time Stack 385
14.3.2 Getting It All to Work 388
14.3.3 Tying It All Together 393
14.4 Problem Solving Using Functions 3 9 4
14.4.1 Problem 1: Case Conversion 395
14.4.2 Problem 2: Pythagorean
Triples 397
14.5 Summary 3 9 8
Exercises 3 9 9
15 Testing and Debugging 407
1 5 . 1 Introduction 4 0 7
15.2 Types of Errors 4 0 8
15.2.1 Syntactic Errors 409
Contents ix
15.2.2 Semantic Errors 409
15.2.3 Algorithmic Errors 411
15.3 Testing 412
15.3.1 Black-Box Testing 412
15.3.2 White-Box Testing 413
15.4 Debugging 414
15.4.1 Ad Hoc Techniques 414
15.4.2 Source-Level Debuggers 415
15.5 Programming for Correctness 417
15.5.1 Nailing Down the
Specification 417
15.5.2 Modular Design 418
15.5.3 Defensive Programming 418
15.6 Summary 419
Exercises 4 2 1
16 Pointers and Arrays 427
16.1 Introduction 427
16.2 Pointers 428
16.2.1 Declaring Pointer Variables 429
16.2.2 Pointer Operators 430
16.2.3 Passing a Reference Using
Pointers 432
16.2.4 Null Pointers 433
16.2.5 Demystifying the Syntax 434
16.2.6 An Example Problem Involving
Pointers 434
16.3 Arrays 436
16.3.1 Declaring and Using
Arrays 436
16.3.2 Examples Using Arrays 438
16.3.3 Arrays as Parameters 440
16.3.4 Strings in C 441
16.3.5 The Relationship Between Arrays and
Pointers in C 446
16.3.6 Problem Solving: Insertion
Sort 446
16.3.7 Common Pitfalls with Arrays
in C 449
16.4 Summary 4 5 1
Exercises 4 5 1
17 Recursion 457
17.1 Introduction 457
17.2 What Is Recursion? 458
17.3 Recursion versus Iteration 459
17.4 Towers of Hanoi 460
17.5 Fibonacci Numbers 464
17.6 Binary Search 468
17.7 Integer to A S C I I 4 7 1
17.8 Summary 473
Exercises 473
18 I/O in C 481
18.1 Introduction 4 8 1
18.2 The C Standard Library 4 8 1
18.3 I/O, One Character at a Time 482
18.3.1 I/O Streams 482
18.3.2 p u t c h a r 483
18.3.3 g e t c h a r 483
18.3.4 Buffered I/O 483
18.4 Formatted I/O 485
18.4.1 p r i n t f 485
18.4.2 s c a n f 487
18.4.3 Variable Argument
Lists 489
18.5 I/O from Files 4 9 1
18.6 Summary 493
Exercises 494
19 Data Structures 497
19.1 Introduction 497
19.2 Structures 498
19.2.1 typedef 500
19.2.2 Implementing Structures
in C 501
19.3 Arrays of Structures 502
19.4 Dynamic Memory Allocation 504
19.4.1 Dynamically Sized Arrays 506
19.5 Linked Lists 508
19.5.1 An Example 510
19.6 Summary 516
Exercises 517
A The LC-3 ISA 521
A . l Overview 5 2 1
A.2 Notation 523
A.3 The Instruction Set 523
A.4 Interrupt and Exception Processing 543
A.4.1 Interrupts 543
A.4.2 Exceptions 544
X Contents
B From LC-3 to x86 547
B . l LC-3 Features and Corresponding x86
Features 548
B . l . l Instruction Set 548
B.l.2 Memory 553
B.l.3 Internal State 553
B.2 The Format and Specification of x86
Instructions 557
B.2.1 Prefix 558
B.2.2 Opcode 559
B.2.3 ModR/M Byte 559
B.2.4 SIB Byte 560
B.2.5 Displacement 560
B.2.6 Immediate 560
B.3 An Example 562
C The Microarchitecture of the
LC-3 565
C . l Overview 565
C.2 The State Machine 567
C.3 The Data Path 569
C.4 The Control Structure 569
C.5 Memory-Mapped I/O 575
C.6 Interrupt and Exception Control 576
C.6.1 Initiating an Interrupt 579
C.6.2 Returning from an Interrupt,
RTI 581
C.6.3 The Illegal Opcode Exception 582
C.7 Control Store 583
D The C Programming
Language 585
D . l Overview 585
D.2 C Conventions 585
D.2.1 Source Files 585
D.2.2 Header Files 585
D.2.3 Comments 586
D.2.4 Literals 586
D.2.5 Formatting 588
D.2.6 Keywords 588
D.3 Types 589
D.3.1 Basic Data Types 589
D.3.2 Type Qualifiers 590
D.3.3 Storage Class 591
D.3.4 Derived Types 592
D.3.5 typedef 594
D.4 Declarations 595
D.4.1 Variable Declarations 595
D.4.2 Function Declarations 596
D.5 Operators 596
D.5.1 Assignment Operators 597
Arithmetic Operators 597
Bit-wise Operators 598
Logical Operators 598
Relational Operators 599
I ncrement/Decrement
Operators 599
Conditional Expression 600
Pointer, Array, and Structure
Operators 600
sizeof 601
Order of Evaluation 602
Type Conversions 602
Expressions and Statements 603
D.6.1 Expressions 603
Statements 604
604
I f 604
If-else 605
Switch 605
While 606
For 607
Do-while 607
Break 608
continue 608
return 609
D.8 The C Preprocessor 609
D.8.1 Macro substitution 609
D.8.2 File inclusion 610
D.9 Some Standard Library Functions 610
D.9.1 I/O Functions 611
D.9.2 String Functions 612
D.9.3 Math Functions 613
D.9.4 Utility Functions 613
D.6
D.7
D.5.2
D.5.3
D.5.4
D.5.5
D.5.6
D.5.7
D.5.8
D.5.9
D.5.10
D.5.11
D.6.2
Control
D.7.1
D.7.2
D.7.3
D.7.4
D.7.5
D.7.6
D.7.7
D.7.8
D.7.9
E Useful Tables 615
E . l Commonly Used Numerical Prefixes
E.2 Standard A S C I I codes 616
E.3 Powers of 2 617
F Solutions to Selected
Exercises 619
615
preface
It is a pleasure to be writing a preface to the second edition of this book. Three
years have passed since the first edition came out. We have received an enormous
number of comments from students who have studied the material in the book
and from instructors who have taught from it. Almost all have been very positive.
It is gratifying to know that a lot of people agree with our approach, and that
this agreement is based on real firsthand experience learning from it (in the case
of students) or watching students learn from it (in the case of instructors). The
excitement displayed in their e-mail continues to be a high for us.
However, as we said in the preface to the first edition, this book will always
be a "work in progress." Along with the accolades, we have received some good
advice on how to make itbetter. We thank you for that. We have also each taught the
course two more times since the first edition came out, and that, too, has improved
our insights into what we think we did right and what needed improvement. The
result has been a lot of changes in the second edition, while hopefully maintaining
the essence of what we had before. How well we have succeeded we hope to soon
learn from you.
Major Changes to [lie First Edition
The LC-3
One of the more obvious changes in the second edition is the replacement of the
LC-2 with the LC-3. We insisted on keeping the basic concept of the LC-2: a
rich ISA that can be described in a few pages, and hopefully mastered in a short
time. We kept the 16-bit instruction and 4-bit opcode. One of our students pointed
out that the subroutine return instruction (RET) was just a special case of LC-2's
JMPR instruction, so we eliminated RET as a separate opcode. The LC-3 specifies
only 15 opcodes—and leaves one for future use (perhaps, the third edition!).
We received a lot of push-back on the PC-concatenate addressing mode,
particularly for branches. The addressing mode had its roots in the old PDP-8 of
the mid-1960s. A majorproblem with it comes up when an instruction on one page
wants to dereference the next (or previous) page. This has been a major hassle,
particularly for forward branches close to a page boundary. A lot of people have
asked us to use the more modern PC+offset, and we agreed. We have replaced all
uses of PC'offset with PC+SEXT(offset).
We incorporated other changes in the LC-3. Stacks now grow toward 0,
in keeping with current conventional practice. The offset in LDR/STR is now
xii preface
a signed value, so addresses can be computed plus or minus a base address.
The opcode 1101 is not specified. The JSR/JMP opcodes have been reorganized
slightly. Finally, we expanded the condition codes to a 16-bit processor status
register (PSR) that includes a privilege mode and a priority level. As in the first
edition, Appendix A specifies the LC-3 completely.
Additional Material
Although no chapter in the book has remained untouched, some chapters have
been changed more than others. We added discussions to Chapter 1 on the nature
and importance of abstraction and the interplay of hardware and software because
it became clear that these points needed to be made explicit. We added a full
section to Chapter 3 on finite state control and its implementation as a sequential
switching circuit because we believe the concept of state and finite state control
are among the most important concepts a computer science or engineering student
encounters. We feel it is also useful to the understanding of the von Neumann
model of execution discussed in Chapter 4. We added a section to Chapter 4 giving
a glimpse of the underlying microarchitecture of the LC-3, which is spelled out in
all its detail in the overhauled Appendix C. We were told by more than one reader
that Chapter 5 was too terse. We added little new material, but lots of figures and
explanations that hopefully make the concepts clearer. We also added major new
sections on interrupt-driven I/O to Chapters 8 and 10.
Just as in the first edition, Chapters 11 through 14 introduce the C program-
ming language. Unlike the first edition, these chapters are more focused on the
essential aspects of the language useful to a beginning programmer. Special-
ized features, for example the C switch construct, are relegated to the ends of
the chapters (or to Appendix D), out of the main line of the text. All of these
chapters include more examples than the first edition. The second edition also
places a heavier emphasis on "how to program" via problem-solving examples
that demonstrate how newly introduced C constructs can be used in C program-
ming. In Chapter 14, students are exposed to a new LC-3 calling convention that
more closely reflects the calling convention used by real systems. Chapter 15
contains a deeper treatment of testing and debugging. Based on our experiences
teaching the introductory course, we have decided to swap the order of the chapter
on recursion with the chapter on pointers and arrays. Moving recursion later (now
Chapter 17) in the order of treatment allows students to gain more experience with
basic programming concepts before they start programming recursive functions.
The Simulator
Brian Hartman has updated the simulator that runs on Windows to incorporate
the changes to the LC-3. Ashley Wise has written an LC-3 simulator that runs on
UNIX. Both have incorporated interrupt-driven I/O into the simulator's function-
ality. We believe strongly that there is no substitute for hands-on practice testing
one's knowledge. With the addition of interrupt-driven I/O to the simulator, the
student can now interrupt an executing program by typing a key on the keyboard
and invoke an interrupt service routine.
preface xiii
Alternate Uses of the Booh
We wrote the book as a textbook for a freshman introduction to computing. We
strongly believe, as stated more completely in the preface to our first edition,
that our motivated bottom-up approach is the best way for students to learn the
fundamentals of computing. We have seen lots of evidence that suggests that in
general, students who understand the fundamentals of how the computer works
are better able to grasp the stuff that they encounter later, including the high-level
programming languages that they must work in, and that they can learn the rules
of these programming languages with far less memorizing because everything
makes sense. For us, the best use of the book is a one-semester freshman course
for particularly motivated students, or a two-semester sequence where the pace
is tempered. If you choose to go the route of a one-semester course heavy on
high-level language programming, you probably want to leave Out the material
on sequential machines and interrupt-driven I/O. If you choose to go the one-
semester route heavy on the first half of the book, you probably want to leave out
much of Chapters 15, 17, 18, and 19.
We have also seen the book used effectively in each of the following
environments:
Two Quarters, Freshman Course
In some sense this is the best use of the book. In the first quarter, Chapters 1
through 10 are covered; in the second quarter, Chapters 11 through 19. The pace
is brisk, but the entire book can be covered in two academic quarters.
One-Semester Second Course
The book has been used successfully as a second course in computing, after
the student has spent the first course with a high-level programming language.
The rationale is that after exposure to high-level language programming in the
first course, the second course should treat at an introductory level digital logic,
basic computer organization, and assembly language programming. Most of the
semester is spent on Chapters 1 through 10, with the last few weeks spent on a few
topics from Chapters 11 through 19, showing how some of the magic from the
students' first course can actually be implemented. Functions, activation records,
recursion, pointer variables, and some elementary data structures are typically the
topics that get covered.
A Sophomore-Level Computer Organization Course
The book has been used to delve deeply into computer implementation in
the sophomore year. The semester is spent in Chapters 1 through 10, sometimes
culminating in a thorough study of Appendix C, which provides the complete
microarchitecture of a microprogrammed LC-3. We note, however, that some
very important ideas in computer architecture are not covered here, most notably
cache memory, pipelining, and virtual memory. We agree that these topics are
very important to the education of a computer scientist or computer engineer, but
we feel these topics are better suited to a senior course in computer architecture
and design. This book is not intended for that purpose.
xhr preface
Acknowledgments
Our book continues to benefit greatly from important contributions of many, many
people. We particularly want to acknowledge Brian Hartman and Matt Starolis.
Brian Hartman continues to be a very important part of this work, both for
the great positive energy he brings to the table and for his technical expertise.
He is now out of school more than three years and remains committed to the
concept. He took the course the first year it was offered at Michigan (Winter
term, 1996), TAed it several times as an undergraduate student, and wrote the
first LC-2 simulator for Windows while he was working on his master's degree.
He recently upgraded the Windows simulator to incorporate the new LC-3.
Matt Starolis took the freshman course at UT two years ago and TAed it as
a junior last fall. He, too, has been very important to us getting out this second
edition. He has been both critic of our writing and helpful designer of many of the
figures. He also updated the tutorials for the simulators, which was necessary in
order to incorporate the new characteristics of the LC-3. When something needed
to be done, Matt volunteered to do it. His enthusiasm for the course and the book
has been a pleasure.
With more than 100 adopters now, we regularly get enthusiastic e-mail with
suggestions from professors from all over the world. Although we realize we
have undoubtedly forgotten some, we would at least like to thank Professors
Vijay Pai, Rice; Richard Johnson, Western New Mexico; Tore Larsen, Tromso;
Greg Byrd, NC State; Walid Najjar, UC Riverside; Sean Joyce, Heidelberg Col-
lege; James Boettler, South Carolina State; Steven Zeltmann, Arkansas; Mike
McGregor, Alberta; David Lilja, Minnesota; Eric Thompson, Colorado, Denver;
and Brad Hutchings, Brigham Young.
Between the two of us, we have taught the course four more times since the
first edition came out, and that has produced a new enthusiastic group of believ-
ers, both TAs and students. Kathy Buckheit, Mustafa Erwa, Joseph Grzywacz,
Chandresh Jain, Kevin Major, Onur Mutlu, Moinuddin Qureshi, Kapil Sachdeva,
Russell Schreiber, Paroma Sen, Santhosh Srinath, Kameswar Subramaniam,
David Thompson, Francis Tseng, Brian Ward, and Kevin Woley have all served
as TAs and have demonstrated a commitment to helping students learn that can
only be described as wonderful. Linda Bigelow, Matt Starolis, and Lester Guillory
all took the course as freshmen, and two years later they were among the most
enthusiastic TAs the course has known.
Ashley Wise developed the Linux version of the LC-3 simulator. Ajay
Ladsaria ported the LCC compiler to generate LC-3 code. Gregory Muthler and
Francesco Spadini enthusiastically provided critical feedback on drafts of the
chapters in the second half. Brian Fahs provided solutions to the exercises.
Kathy Buckheit wrote introductory tutorials to help students use the LC-2
simulator because she felt it was necessary.
Several other faculty members at The University of Texas have used the book
and shared their insights with us: Tony Ambler, Craig Chase, Mario Gonzalez,
and Earl Swartzlander in ECE, and Doug Burger, Chris Edmundson, and Steve
Keckler in CS. We thank them.
preface xv
We continue to celebrate the commitment displayed by our editors, Betsy
Jones and Michelle Flomenhoft.
As was the case with the first edition, our book has benefited from exten-
sive reviews provided by faculty members from many universities. We thank
Robert Crisp, Arkansas; Allen Tannenbaum, Georgia Tech; Nickolas Jovanovic,
Arkansas-Little Rock; Dean Brock, North Carolina-Asheville; Amar Raheja, Cal
State-Pomona; Dayton Clark, Brooklyn College; William Yurcik, Illinois State;
Jose Delgado-Frias, Washington State; Peter Drexel, Plymouth State; Mahmoud
Manzoul, Jackson State; Dan Connors, Colorado; Massoud Ghyam, Southern
Cal; John Gray, UMass-Dartmouth; John Hamilton, Auburn; Alan Rosenthal,
Toronto; and Ron Taylor, Wright State.
Finally, there are those who have contributed in many different and often
unique ways. Without listing their individual contributions, we simply list them
and say thank you. Amanda, Bryan, and Carissa Hwu, Mateo Valero, Rich
Belgard, Janak Patel, Matthew Frank, Milena Milenkovic, Lila Rhoades, Bruce
Shriver, Steve Lumetta, and Brian Evans. Sanjay would like to thank Ann Yeung
for all her love and support.
f) Final Word
It is worth repeating our final words from the preface to the first edition: We are
mindful that the current version of this book will always be a work in progress,
and we welcome your comments on any aspect of it. You can reach us by e-mail
at patt@ece.utexas.edu and sjp@crhc.uiuc.edu. We hope you will.
Yale N. Patt
Sanjay J. Patel
May, 2003
preface to the first edition
This textbook has evolved from EECS 100, the first computing course for com-
puter science, computer engineering, and electrical engineering majors at the
University of Michigan, that Kevin Compton and the first author introduced for
the first time in the fall term, 1995.
EECS 100 happened because Computer Science and Engineering faculty
had been dissatisfied for many years with the lack of student comprehension of
some very basic concepts. For example, students had a lot of trouble with pointer
variables. Recursion seemed to be "magic," beyond understanding.
We decided in 1993 that the conventional wisdom of starting with a high-
level programming language, which was the way we (and most universities) were
doing it, had its shortcomings. We decided that the reason students were not
getting it was that they were forced to memorize technical details when they did
not understand the basic underpinnings.
The result is the bottom-up approach taken in this book. We treat (in order)
MOS transistors (very briefly, long enough for students to grasp their global
switch-level behavior), logic gates, latches, logic structures (MUX, Decoder,
Adder, gated latches), finally culminating in an implementation of memory. From
there, we move on to the Von Neumann model of execution, then a simple com-
puter (the LC-2), machine language programming of the LC-2, assembly language
programming of the LC-2, the high level language C, recursion, pointers, arrays,
and finally some elementary data structures.
We do not endorse today's popular information hiding approach when it
comes to learning. Information hiding is a useful productivity enhancement tech-
nique after one understands what is going on. But until one gets to that point, we
insist that information hiding gets in the way of understanding. Thus, we contin-
ually build on what has gone before, so that nothing is magic, and everything can
be tied to the foundation that has already been laid.
We should point out that we do not disagree with the notion of top-down
design. On the contrary, we believe strongly that top-down design is correct
design. But there is a clear difference between how one approaches a design
problem (after one understands the underlying building blocks), and what it takes
to get to the point where one does understand the building blocks. In short, we
believe in top-down design, but bottom-up learning for understanding.
Htiaf Is in the Booh
The book breaks down into two major segments, a) the underlying structure of a
computer, as manifested in the LC-2; and b) programming in ahigh level language,
in our case C.
The LC-2
We start with the underpinnings that are needed to understand the workings of a
real computer. Chapter 2 introduces the bit and arithmetic and logical operations
on bits, Then we begin to build the structure needed to understand the LC-2.
Chapter 3 takes the student from a MOS transistor, step by step, to a real memory.
Our real memory consists of 4 words of 3 bits each, rather than 64 megabytes. The
picture fits on a single page (Figure 3.20), making it easy for a student to grasp.
By the time the students get there, they have been exposed to all the elements that
make memory work. Chapter 4 introduces the Von Neumann execution model,
as a lead-in to Chapter 5, the LC-2.
The LC-2 is a 16-bit architecture that includes physical I/O via keyboard and
monitor; TRAPs to the operating system for handling service calls; conditional
branches on N, Z, and P condition codes; a subroutine call/return mechanism; a
minimal set of operate instructions (ADD, AND, and NOT); and various address-
ing modes for loads and stores (direct, indirect, Base+offset, and an immediate
mode for loading effective addresses).
Chapter 6 is devoted to programming methodology (stepwise refinement) and
debugging, and Chapter 7 is an introduction to assembly language programming.
We have developed a simulator and an assembler for the LC-2. Actually, we have
developed two simulators, one that runs on Windows platforms and one that runs
on UNIX. The Windows simulator is available on the website and on the CD-
ROM. Students who would rather use the UNIX version can download and install
the software from the web at no charge.
Students use the simulator to test and debug programs written in LC-2
machine language and in LC-2 assembly language. The simulator allows online
debugging (deposit, examine, single-step, set breakpoint, and so on). The sim-
ulator can be used for simple LC-2 machine language and assembly language
programming assignments, which are essential for students to master the concepts
presented throughout the first 10 chapters.
Assembly language is taught, but not to train expert assembly language pro-
grammers. Indeed, if the purpose was to train assembly language programmers,
the material would be presented in an upper-level course, not in an introductory
course for freshmen. Rather, the material is presented in Chapter 7 because it
is consistent with the paradigm of the book. In our bottom-up approach, by the
time the student reaches Chapter 7, he/she can handle the process of transform-
ing assembly language programs to sequences of 0s and Is. We go through the
process of assembly step-by-step for a very simple LC-2 Assembler. By hand
assembling, the student (at a very small additional cost in time) reinforces the
important fundamental concept of translation.
It is also the case that assembly language provides a user-friendly notation
to describe machine instructions, something that is particularly useful for the
xxii preface to the first edition
second half of the book. Starting in Chapter 11, when we teach the semantics of
C statements, it is far easier for the reader to deal with ADD Rl, R2, R3 than with
0001001010000011.
Chapter 8 deals with physical input (from a keyboard) and output (to a mon-
itor). Chapter 9 deals with TRAPs to the operating system, and subroutine calls
and returns. Students study the operating system routines (written in LC-2 code)
for carrying out physical I/O invoked by the TRAP instruction.
The first half of the book concludes with Chapter 10, a treatment of stacks
and data conversion at the LC-2 level, and a comprehensive example that makes
use of both. The example is the simulation of a calculator, which is implemented
by a main program and 11 subroutines.
The Language C
From there, we move on to C. The C programming language occupies the second
half of the book. By the time the student gets to C, he/she has an understanding
of the layers below.
The C programming language fits very nicely with our bottom-up approach.
Its low-level nature allows students to see clearly the connection between software
and the underlying hardware. In this book we focus on basic concepts such as
control structures, functions, and arrays. Once basic programming concepts are
mastered, it is a short step for students to learn more advanced concepts such as
objects and abstraction.
Each time a new construct in C is introduced, the student is shown the LC-2
code that a compiler would produce. We cover the basic constructs of C (vari-
ables, operators, control, and functions), pointers, recursion, arrays, structures,
I/O, complex data structures, and dynamic allocation.
Chapter 11 is a gentle introduction to high-level programming languages. At
this point, students have dealt heavily with assembly language and can understand
the motivation behind what high-level programming languages provide. Chapter
11 also contains a simple C program, which we use to kick-start the process of
learning C.
Chapter 12 deals with values, variables, constants, and operators. Chapter 13
introduces C control structures. We provide many complete program examples
to give students a sample of how each of these concepts is used in practice. LC-2
code is used to demonstrate how each C construct affects the machine at the lower
levels.
In Chapter 14, students are exposed to techniques for debugging high-level
source code. Chapter 15 introduces functions in C. Students are not merely
exposed to the syntax of functions. Rather they learn how functions are actually
executed using a run-time stack. A number of examples are provided.
Chapter 16 teaches recursion, using the student's newly gained knowledge of
functions, activation records, and the run-time stack. Chapter 17 teaches pointers
and arrays, relying heavily on the student's understanding of how memory is
organized. Chapter 18 introduces the details of I/O functions in C, in particular,
xxii preface to the first edition
streams, variable length argument lists, and how C I/O is affected by the various
format specifications. This chapter relies on the student's earlier exposure to
physical I/O in Chapter 8. Chapter 19 concludes the coverage of C with structures,
dynamic memory allocation, and linked lists.
Along the way, we have tried to emphasize good programming style and
coding methodology by means of examples. Novice programmers probably learn
at least as much from the programming examples they read as from the rules they
are forced to study. Insights that accompany these examples are highlighted by
means of lightbulb icons that are included in the margins.
We have found that the concept of pointer variables (Chapter 17) is not at all
a problem. By the time students encounter it, they have a good understanding of
what memory is all about, since they have analyzed the logic design of a small
memory (Chapter 3). They know the difference, for example, between a memory
location's address and the data stored there.
Recursion ceases to be magic since, by the time a student gets to that point
(Chapter 16), he/she has already encountered all the underpinnings. Students
understand how stacks work at the machine level (Chapter 10), and they under-
stand the call/return mechanism from their LC-2 machine language programming
experience, and the need for linkages between a called program and the return to
the caller (Chapter 9). From this foundation, it is not a large step to explain func-
tions by introducing run-time activation records (Chapter 15), with a lot of the
mystery about argument passing, dynamic declarations, and so on, going away.
Since a function can call a function, it is one additional small step (certainly no
magic involved) for a function to call itself.
Horn to Use This Booh
We have discovered over the past two years that there are many ways the material
in this book can be presented in class effectively. We suggest six presentations
below:
1. The Michigan model. First course, no formal prerequisites. Very intensive,
this course covers the entire book. We have found that with talented, very
highly motivated students, this works best.
2. Normal usage. First course, no prerequisites. This course is also intensive,
although less so. It covers most of the book, leaving out Sections 10.3 and
10.4 of Chapter 10, Chapters 16 (recursion), 18 (the details of C I/O), and
19 (data structures).
3. Second course. Several schools have successfully used the book in their
second course, after the students have been exposed to programming with
an object-oriented programming language in a milder first course. In this
second course, the entire book is covered, spending the first two-thirds of
the semester on the first 10 chapters, and the last one-third of the semester
on the second half of the book. The second half of the book can move
more quickly, given that it follows both Chapters 1-10 and the
preface to the first edition xxi
introductory programming course, which the student has already taken.
Since students have experience with programming, lengthier
programming projects can be assigned. This model allows students who
were introduced to programming via an object-oriented language to pick
up C, which they will certainly need if they plan to go on to advanced
software courses such as operating systems.
4. Two quarters. An excellent use of the book. No prerequisites, the entire
book can be covered easily in two quarters, the first quarter for Chapters
1-10, the second quarter fcr Chapters 11-19.
5. Two semesters. Perhaps the optimal use of the book. A two-semester
sequence for freshmen. No formal prerequisites. First semester, Chapters
1-10, with supplemental material from Appendix C, the Microarchitecture
of the LC-2. Second semester, Chapters 11-19 with additional substantial
programming projects so that the students can solidify the concepts they
learn in lectures.
6. A sophomore course in computer hardware. Some universities have found
the book useful for a sophomore level breadth-first survey of computer
hardware. They wish to introduce students in one semester to number
systems, digital logic, computer organization, machine language and
assembly language programming, finishing up with the material on stacks,
activation records, recursion, and linked lists. The idea is to tie the
hardware knowledge the students have acquired in the first part of the
course to some of the harder to understand concepts that they struggled
with in their freshman programming course. We strongly believe the better
paradigm is to study the material in this book before tackling an
object-oriented language. Nonetheless, we have seen this approach used
successfully, where the sophomore student gets to understand the concepts
in this course, after struggling with them during the freshman year.
Some Observations
Understanding, Not Memorizing
Since the course builds from the bottom up, we have found that less memorization
of seemingly arbitary rules is required than in traditional programming courses.
Students understand that the rules make sense since by the time a topic is taught,
they have an awareness of how that topic is implemented at the levels below it. This
approach is good preparation for later courses in design, where understanding of
and insights gained from fundamental underpinnings are essential to making the
required design tradeoffs.
The Student Debugs the Student's Program
We hear complaints from industry all the time about CS graduates not being able
to program. Part of the problem is the helpful teaching assistant, who contributes
far too much of the intellectual component of the student's program, so the student
Discovering Diverse Content Through
Random Scribd Documents
"You saved my life, youngster, and I won't forget it. Come aboard
my ship before sailing and let me thank you, won't you? I'll be fit
and hearty in a day or so."
Dan liked the looks and manner of the big, brown-bearded
Englishman and warmly replied:
"Pulling you out of the wet was the least we could do. I hope your
head will mend all right. Captain Wetherly will be glad to see you on
board again, sir."
Dan lent a hand as far as the hack and then sought Captain
Wetherly's room. The light was burning and the deck-hand dared to
enter on the chance of having a talk with "Uncle Jim," whom he
found reading a novel in his bunk. The boy had many questions to
ask, but he was not ready to go straight to the heart of the matter,
and so began:
"Jerry Pringle acted kind of ugly and uneasy, didn't you think? I
suppose he was mad at getting spilled into the harbor. You and he
never did seem to be very fond of each other."
Captain Jim threw down his book and sat up in his bunk with a
rather grim smile as he replied:
"You're no fool, Dan, though you aren't more than half as old as me.
And you have lived ten of your years in Key West. I know you think
the world of young Barton Pringle. He is a fine, clean lad, the son of
his mother through and through. But there's a different strain in that
dad of his, and you know it. You want to find out what I think of to-
night's business, don't you? Well, I think the big Englishman might
have picked better company."
"But he said some things about getting ten thousand dollars for
losing his ship and so on, Uncle Jim, and I heard more than you did.
He was worried to death for fear he had talked too much. The
wrecking business in Key West is square and honest as far as I
know, but ship captains have put their vessels on the Reef on
purpose in the old days and the wreckers helped plan it beforehand.
And I can't help wondering if Jerry Pringle came to Pensacola to fix
up a deal with this captain of the Kenilworth to lose his ship on the
next voyage out from London to Vera Cruz. There would be rich
salvage and loot in a general cargo, wouldn't there? She's a mighty
big steamer."
Captain Jim stroked his chin and was so long silent that Dan began
to fidget. Then, as if rousing himself from some very interesting
reflections, the elder man drawled in a tone of mild reproof:
"There isn't a bit of evidence that would hold water, Dan. I may have
my suspicions, but perhaps they are all wrong, and if we said a word
it might ruin a good ship-master with his owners. Jerry Pringle and
he must have been up to their ears in conversation when they let us
run 'em under, and I wish the big Englishman could prove an alibi for
the time we had him, aboard. Better forget it."
Dan bit his lip and appeared so gloomy and forlorn that his uncle
was moved to ask what troubled him.
"It's Bart Pringle," said Dan, and his voice was not quite steady.
"When I meet him in Key West I'll have a secret to hold back from
him, and it's about his own father. Oh, I can't believe there's
anything to it. And there's Bart's mother! Well, I think I'll turn in,
Uncle Jim. Good-night."
Late in the next afternoon the Resolute cast off from the coal wharf
and swiftly picked up headway as her powerful engines began to
urge her, with tireless, throbbing cadence, toward her distant home
port of Key West. Presently she surged past a long, deep-laden
cargo steamer from whose stern rippled the flaming British ensign. It
was the Kenilworth, and Captain Jim and Dan Frazier stared at her
with curious interest.
A tall, broad-shouldered, brown-bearded figure was leaning against
the railing of her bridge. A strip of bandage gleamed white beneath
the visor of his cap. He flourished an arm in farewell to the Resolute
whose deep-toned whistle returned a salute of three blasts.
Dan passed by the wheel-house door on an errand for the mate and
could not help saying aloud to himself:
"It must have been a nightmare. That Captain Bruce looks like too
fine a man to think of such a dreadful thing!"
Captain Jim Wetherly overheard the comment and seemed to echo
this verdict as he remarked in a reverent and sympathetic tone:
"Lead Captain Malcolm Bruce not into temptation, for Jerry Pringle is
a hard customer to have any dealings with, on or off the Reef."
CHAPTER II
THE "RESOLUTE" FATHOMS THE PLOT
As the Resolute steamed into Key West harbor, Dan Frazier was on
the lookout for his friend Barton Pringle who almost always ran down
to the wharf when the whistle of Captain Wetherly's tug bellowed
the tidings of her return from sea. This time, however, Dan felt that
a shadow had fallen over their close comradeship which had been
wholly frank and confiding through all their years together. Dan
could not forget the events of the night in which Barton's father had
behaved like a man caught in the act of planning something dark
and evil.
But the sight of Barton Pringle waiting on the end of the wharf to
catch the Resolute's heaving lines and welcome him home, made
Dan wonder afresh if he had not been too hasty and suspicious.
Barton's honest, beaming face was in itself a voucher for his bringing
up amid sweet and wholesome influences. Nor was Dan ready to
believe that a bad father could have such a straight and manly son.
Before the boys were within shouting range of each other, Captain
Wetherly sent for Dan and told him:
"You can stay home until you get further orders. I don't expect to
leave port again for several days. Tell your mother that I will run in
for a little while after supper to-night."
Dan thanked him with a grin of delight and ran below to yell to
Barton Pringle on the wharf:
"Hello, Bart. Come aboard and help me scrub decks and get things
ship-shape and I'll be ready to jump ashore just so much sooner."
Barton made a flying leap aboard as soon as the lines were made
fast, and asked as he picked up a pail and broom:
"What kind of a voyage did you have, Dan? Anything exciting
happen?"
"Nothing to speak of," replied Dan, and he felt his face redden with a
guilty sense of secrecy. He was about to say that he had met
Barton's father in Pensacola, without mentioning how or where,
when the other lad spoke up:
"I tried to get away for a little trip myself. Father went up the Gulf on
the mail steamer and I begged him to take me along. But he was
going only to Tampa to see about buying a couple of sponging
schooners, and he said he was in too much of a hurry to bother with
me."
"Going only to Tampa," echoed Dan with a foolish smile. "Oh, yes,
only as far as Tampa. Sorry you had to miss it, Bart. How's
everything with you? Have you bent the new main-sail on the
Sombrero?"
Barton plunged into an excited discussion about the fast little sloop
which the boys owned in partnership, while Dan tried to keep his
wits about him, for he was thrown into fresh doubt and uneasiness
by the news that Jeremiah Pringle had said he was going to Tampa
instead of Pensacola. Usually the two boys had so many important
matters to talk about that one could find a chance to break in only
when the other paused for lack of breath, but now Dan found it hard
to avoid awkward silences on his part. He was glad when old Bill
McKnight, the chief engineer of the Resolute, waddled up to them
and announced with a sweeping gesture toward the city streets:
"Back again to the palm trees and the brave Cubanos and the
excitements of a metropolis smeared over a chunk of coral reef so
blamed small that I'm scared to be out after dark without a lantern
for fear I'll walk overboard. I'm due to start a revolution in
Honduras, and to-day I enlist a few hundred brave and desperate
Key West cigar-makers, Dan. I'm perishin' for a little war and tumult.
Look out for my signal rockets."
With that Mr. McKnight jauntily twirled his grizzled moustache and
ambled up the wharf. He had been engineer of the Resolute when
she was running the Spanish blockade of Cuba, as a filibuster to
carry arms and ammunitions to the revolutionists, and his cool-
headed courage had fetched the tug out of some perilous places.
The ponderous, good-natured engineer was very fond of Dan and
every little while invited him, with all seriousness, to join some new
and absurd scheme for touching off a Spanish-American revolution,
with dazzling promises of loot and glory.
The boys laughed as they gazed after him, and Barton said:
"Filibustering must keep your hair standing on end, eh, Dan? I
reckon it beats wrecking, though you couldn't get an old Key Wester
to admit it. There hasn't been a wreck on the Reef for goodness
knows how long. Father promised to take me with him on the next
wrecking job if it isn't blowing too hard when the schooners go out
to the Reef."
"Well, you can count on seeing Captain Jim Wetherly and the
Resolute on the job no matter how hard she blows," smiled Dan with
a spark of the rivalry which flamed high between the tow-boat and
the schooner fleet. Willing hands made short work of Dan's tasks,
and he hurried into his shore-going clothes while Barton swung his
legs from the bunk and retailed the latest news about ships, and the
sponge market, and the High School base-ball team which had won
a match from the soldiers of the garrison. They parted a little later,
Dan eager to run home and see his mother, and Barton anxious to
make the Sombrero ready for a trial spin.
As Dan sped toward the cottage on the other side of the narrow
island, he said to himself with a puzzled frown:
"Everything Bart talked about made me think of the other night in
Pensacola: his father's going away, and the next wreck on the Reef,
and all that. And he thinks his father is the strongest, bravest man
that ever went to sea. Maybe he is, but I wish he wasn't related to
Bart."
A slender, sweet-faced woman in black was waiting in a dooryard
shaded by tropical verdure as Dan rounded the corner. She had
heard the far-echoing, resonant whistle of the Resolute, and knew
that her boy was home again. Her husband, for many years
employed in the Key West Custom House, had died only two years
before, and the love and yearning in her eyes at sight of Dan would
have told you that he was her only child and her all-in-all if you had
never seen them together before. He was taller than she, and, as
her sturdy son stooped to kiss her with his arms about her neck, she
said:
"I wanted to be at the wharf to meet you, Danny boy, but I couldn't
leave home in time. Bart Pringle's mother ran in to talk to me about
sending him away to school. I told her I wanted to do as much for
you, but the way wasn't open yet. They can afford it, and Bart is too
bright and ambitious to settle down in a Key West rut."
They walked to the wide veranda across which the cool trade-wind
swept, and Mrs. Frazier ordered Dan to take the biggest, easiest
wicker chair, after which she vanished indoors and almost instantly
reappeared with a plate laden with pie and doughnuts.
"You had breakfast in that stuffy little galley, I suppose," laughed
she, "but I know you are always hungry. You can stow these trifles
away as a deck-load, can't you?"
Dan confessed that he could carry any amount of cargo of this kind
and then, between bites of a home-made doughnut, spoke very
earnestly:
"Bart ought to go North to school, mother, and I will tell him so and
back you up for all I'm worth. It will do him good to break away
from home. And Uncle Jim Wetherly will put up the same line of
argument to Mrs. Pringle whenever you say the word."
"Jim is my dearest brother, but I can't picture him as showing very
much excitement about Bart's education," she responded. "He thinks
there's no finer thing in the world than to be master and owner of a
sea-going tow-boat. Why do you think he will be interested, Dan?"
Her son took her hand in his hard, sun-burned paw and with a
stammering effort began his confession of all that he had heard and
seen after Jerry Pringle and the English ship-master had been run
down in their small boat. The mother listened with wide-eyed
astonishment, and then with something like indignation she cried:
"Why, Dan, you ought to be writing novels for a living! That poor
Captain Bruce of the Kenilworth was out of his head, and you know
that Jerry Pringle has a sour, gruff way with him even when he's on
dry land. I can't believe it of Mary Pringle's husband. It is a dreadful
thing to suspect him of, plotting to wreck a fine, big steamer."
"That's just like a woman," declared Dan with a very grown-up air of
wisdom. "Mrs. Pringle hasn't anything to do with it. And you are like
Uncle Jim, always refusing to think other folks are a bit less square
and decent than you are. Ask him to-night what he thinks about it,
but don't breathe a word to anybody else, will you?"
"I shall scold him for putting such silly ideas in your head," firmly
announced Mrs. Frazier. "You couldn't have pieced this plot together
all by yourself, even if you are as big and strong as a young tow-
boat."
"All right," said Dan good-humoredly. "Only I hope Barton will go
away to school before the explosion happens. For if I'm right, Jerry
Pringle may be in disgrace before he's a year older. Captain Jim will
never let up on him if the Kenilworth does happen to be stranded on
the Reef."
When Captain Wetherly strolled in after supper, his sister began at
once to cross-question him. He evaded her as far as possible and
finally declared:
"I knew that Dan would tell you. I don't want him to keep anything
from his mother. But it must go no farther than this. I will say this
much, that when the Kenilworth is due in the Florida Straits on her
next voyage outward bound, the Resolute will be a good deal less
than a thousand miles away. And just for curiosity I have cabled to
London to find out if she is really chartered to Vera Cruz for her next
voyage, and what kind of a reputation her owners bear. They may
be interested in losing her, do you see?
"Speaking of cables, Dan," he continued; "I got orders this afternoon
to go to Charleston at once and tow that big suction dredge to
Santiago. We shall be able to get away in a couple of days. You had
better come aboard to-morrow night."
"Why, you'll be gone for weeks and weeks, Dan," sorrowfully cried
his mother.
"I won't waste any time, nor try to save coal on this voyage," said
Captain Jim with a grim smile. "I want to be a good deal nearer the
Reef than Santiago, about two months from now."
"It's a long, long while to have my boy away from me," Mrs. Frazier
murmured with a sigh. "But this tremendous conspiracy will be all
blown out of your heads before you come home again."
After a luxurious night's slumber in a real bed, Dan felt as if the
cobwebs had been brushed from his busy brain and that the bright
world held better employment than brooding over what might
happen to somebody else. He set forth to find Barton and arrange a
match race between the Sombrero and a rival craft, to be sailed
before Dan had to go to sea. The challenge being accepted on the
spot, there was much to be done in a very few hours, and Dan
heartily agreed with Barton's opinion delivered from the cockpit of
their rakish craft:
"It is a pity we have anything to do but sail boats for the fun of it.
What a bully sou'west breeze we're going to have this afternoon,
Dan! Can you coax old Bill McKnight to come along for ballast?"
"Yes, if we promise him to smuggle some rifles and dynamite in the
hold," laughed the other.
After dinner, Dan sauntered along the water front in the hope of
finding the mighty bulk of the chief engineer to serve as two
hundred and seventy pounds of desirable live ballast. The south-
bound mail steamer, from Tampa for Havana, had just landed her
passengers, and foremost among them loomed the tail and lanky
figure of Jeremiah Pringle. The wrecking master spied Dan and
hurried to meet him in the narrow street. His manner was no longer
hostile and sullen, and Dan was amazed to have a greeting hand
stretched toward him and to hear a cordial voice:
"How's the boy? You and Bart as busy as ever? I went up the Gulf to
buy a schooner or two, and I found a beauty. I need a mate for her,
Dan. You are young, but you know more about salt water than most
men. It means double the wages of a deck-hand on that sooty old
tow-boat. I want you to go to Tampa and help fetch her down right
away, which is why I spring the proposition on you kind of off-hand
and sudden."
It was a chance at which Dan would have jumped a week before.
Something held him back, however, and, although he did not take
time to reason it out, he vaguely felt that Jeremiah Pringle was
trying to bribe him to keep his mouth shut. But he had a natural fear
of making an enemy of such a man as this, and he swiftly decided to
make no mention of the night in Pensacola. That was a matter for
Captain Jim Wetherly to handle. Dan was ready to stand by his guns,
however, so far as his own honesty was concerned, and he stoutly
replied:
"That is a big thing to have come my way, Captain Pringle, and I
ought to thank you. But I don't care to take it. My mother wants me
to stick by Captain Jim Wetherly if I'm going to stay afloat, and she
knows best."
Jerry Pringle looked black, but forced a smile as he growled:
"One thing you've got from your Uncle Jim is a swelled head. Well,
we'll say no more about it; nothing at all about it, understand?"
The last words were spoken with a threatening earnestness, and
Dan understood what was meant. He nodded and went on his way,
for once anxious to get to sea, away from a situation in which he
seemed to become more and more befogged. He found Bart dancing
jig-steps with impatience, and trying to listen to a long-winded yarn
delivered by Mr. Bill McKnight who had been already kidnapped for
the afternoon.
The Sombrero sailed like a witch in the race, the live ballast shifted
himself with more agility than the boys had dreamed he could
display, and the match was won with the lee-rail under and the
cockpit awash. Mrs. Frazier watched the finish from a wharf and
invited Bart and the engineer to come home with Dan for a festive
supper party in celebration. There could be no long faces or heavy
thoughts at such a time, and Dan forgot the shadow and laughed
himself into a state of collapse along with his mother and Bart when
Mr. McKnight, with a wreath of scarlet ponciana blossoms on his bald
head, danced Spanish fandangos until the cottage shook from floor
to rafters.
The Sombrero sailed like a witch in the race
They all escorted Dan down to the Resolute in the starlit evening
and sat on the guard-rail while the chief engineer fished a guitar
from under his bunk and sang Cuban serenades, leading off with "La
Paloma." It was as merry as such a parting hour could be, but there
were tears in the mother's eyes when she kissed Dan good-night,
and her voice was not steady when she whispered, "God bless and
keep you, my precious boy."
When it came to saying good-by to Bart, Dan was more serious than
usual and, he held fast to his comrade's hand for a moment while he
looked him in the eyes and said:
"Blow high, blow low, you will find me standing by, Bart. Good luck
and lots of it."
Shortly after daylight next morning the Resolute churned her way
out of the placid harbor and laid her coastwise course for
Charleston. It proved to be an uneventful run with pleasant weather
and a favoring sea. Captain Wetherly had nothing to say about the
steamer Kenilworth until they reached Charleston where he found a
cablegram from London waiting for him. He read it aloud to Dan as
soon as they happened to be alone.
"Unable to send required information until later. Will communicate
your next port."
"It might have cleared up this Kenilworth business," said Captain
Jim. "However, we may get a message at Santiago."
But the Resolute was not to see Santiago as soon as her master
expected. There was a week's delay in getting the great suction
dredge ready to begin the voyage. Then, when the Resolute had
taken hold of the clumsy monster, for all the world like a bull-dog
trying to drag a dry-goods box, the captain of the dredge was hurt
by a falling bolt and there was more delay at anchor while a new
skipper could be sent for.
When, at last, the unwieldy tow was got to sea, strong head-winds
buffeted her day after day and urged the panting, sea-swept
Resolute to her best efforts to keep up steerage way. She crept
southward like a snail, eating up coal at a rate which compelled
Captain Wetherly to put into Nassau, and again into the harbor of
Mole St. Nicolas at the western end of Hayti.
Twice the dredge snapped her hawsers and broke clean adrift. When
the weary tug and her tow crept in sight of the Morro Castle at the
mouth of Santiago harbor, Bill McKnight almost wept as he surveyed
his engines and boilers. Sorely racked and strained they were, and
Captain Jim tried to comfort him by declaring that no other fat
engineer could have patched and held them together to the end of
the voyage. Making temporary repairs was a costly and tedious
undertaking, and the crew of the Resolute tired of the charms of
Santiago and grew restless and homesick for Key West.
While Dan, the captain, and McKnight were eating lunch ashore one
day, a swarthy, dapper clerk from the cable office sought the Venus
Café with a message which he had tried to deliver on board the tug.
It was for Captain Wetherly who read it with an air of mingled
surprise and chagrin. With a glance at the engineer who was
blissfully absorbed over his third plate of alligator pear salad, Captain
Jim remarked as he handed the sheet to Dan:
"It is from London. Well, the cat is out of the bag, and we might as
well let McKnight in. We are going to need him before we get
through with this job, and need him bad. I suppose I ought to have
been more suspicious, but it sounded too rotten to be true. Bill, you
must have that engine room in shape this week if it breaks your
back. We are going to make a record run home to Key West."
Dan read in silence before handing the cablegram to Captain
Wetherly.
"Kenilworth cleared for Vera Cruz. Heavily insured. General cargo.
Owners hard hit by recent losses. Will bear watching."
Captain Jim hammered the table with his fist and tried to speak in
an undertone as he hotly exclaimed:
"This confidential report makes my suspicions fit together like the
pieces of a puzzle. I couldn't for the life of me understand how the
master of a big steamer could afford to ram her ashore and lose her,
and his berth and his reputation with it, for ten thousand dollars. But
if he knew that his owners would shield him and stand in with him,
why, of course, he might be tempted to clean up ten thousand
dollars for himself when a man like Jerry Pringle crossed his bows
and passed him a few hints. A lot of good it would have done for me
to cable Captain Bruce's owners and give them warning of what we
heard that night in Pensacola harbor. They would have laughed at
me as a meddlesome idiot. Cleared for Vera Cruz, has she? She does
her ten knots right along, I picked up that bit of information at
Pensacola. Allow her twenty days to the Reef."
Bill McKnight had dropped his fork and was purple with suppressed
excitement. When the captain fetched up for lack of breath, he
blurted in a hoarse whisper:
"It doesn't take a axe to drive an idea into my noddle. As near as I
can make out, though your bearings are considerably overheated,
Captain, there is scheduled to be a large and expensive wreck on the
Reef, assisted by her skipper and one Jeremiah Pringle. It sounds
like the good old times before the light-houses crippled the wrecking
industry. And we Resolutes propose to be first on hand to pull her off
and disappoint certain enterprising persons?"
"Disappoint 'em!" fairly shouted Captain Jim. "If the Kenilworth does
go ashore, I'll fetch that vessel off the Reef if it tears the Resolute to
kindling wood. I'll break their rotten hearts and show them what
honest wrecking is."
"I didn't throw away that clamp I made to hold the safety-valve
down, Captain," chuckled Bill McKnight. "And I ain't afraid to use it
again, either."
CHAPTER III
THE RACE FOR THE "KENILWORTH"
Chief Engineer Bill McKnight hoisted himself up the iron ladder that
led from the fire-room of the Resolute and tottered on deck gasping
for breath. He was begrimed from head to foot, the sweat had
furrowed little streaks in the mask of soot and grease which covered
his ample countenance, and his eyes were red with weariness and
want of sleep. He had shoved the tug back to Key West at her top
speed, and now he was toiling night and day to make her ready for
whatever summons might come for a tussle on the Reef. Captain
Wetherly found him slumped against the deck-house with his head in
his hands and exhorted him cheerily:
"Don't give up the ship, Bill. It is a great repair job that you've done,
and the worst is over. The new tubes are most all in, aren't they?"
"The boilers will be as good as new," grunted McKnight, "but how
about my bronchial tubes, Captain? I can't plug them up and make
steam same as I plugged the boilers and fetched you back from
Santiago. I'm so full of cinders inside that I rattle when I walk. But
give me another week and the boat will be fit to hitch a hawser to
this benighted island of Key West and tow it out to sea. Anything
new ashore?"
Captain Jim sat down beside the engineer and made sure that they
could not be overheard as he began:
"Dan has been watching Jerry Pringle's fleet of wrecking vessels for
me. Those two schooners he bought in the Gulf have come into port,
and it is mighty little sponging he intends to do with them at
present, Bill. They look fast and they can stow lots of cargo. And
Pringle has been overhauling his other schooners and has chartered
three more in Key West. He says he intends to send them out to join
the mackerel fleet."
"Anything doing in the tow-boat line?" asked McKnight with a new
gleam of interest in his damaged eyes. "If Pringle aims to tackle a
certain job that may be reported from the Reef pretty soon, he will
have to make a bluff at pulling the steamer off, won't he? There
might be a small fortune in salvage, besides looting the cargo out of
her."
"He is dickering for some kind of a time charter on the Henry
Foster," snapped Captain Jim. "She couldn't pull a feather-bed off
the Reef without breaking down. And I understand he has been
cabling up the Gulf about another tug or two."
"Well, we can get all the tow-boats we need and good ones, can't
we?" beamed McKnight. "Maybe we can't handle most any kind of a
wrecking job ourselves! And there won't be any bluffs about it when
we take hold."
"I'm certainly sorry for Dan, poor boy," said Captain Jim with a sigh.
"He feels as if he were spying on Bart's father. And to make it worse,
Bart is going to sail with the old man for a while and the lad will be
mixed up in this nasty mess as sure as fate, and he will be on the
wrong side of it. Here comes our Dan now. Drop the subject, Bill. It
only makes the youngster more unhappy."
Dan Frazier had passed some restless nights since his return to Key
West, but his mind was too sunny and youthful to believe that things
were ever as bad as they might be. He found comfort in the hope
that Captain Wetherly would spoil the plot to lose the Kenilworth. He
had implicit confidence in his uncle's ability to win against any odds
with the stanch Resolute, and now that a fair and open battle
against Jerry Pringle was assured, Dan found himself eager for the
fray. Barton had told him that morning:
"Father and mother are talking of sending me North to school, but
I'm going to rough it at sea with father for a month or so. He said he
tried to get you to work for him. I knew you wouldn't leave Captain
Jim, but maybe we might have been lucky enough to work on a
wreck together."
"You can't tell, Bart. Perhaps we shall, but we may be working
against each other. I'll back Captain Jim Wetherly to be first man
aboard the next vessel that goes on the Reef."
"Captain Jim is a good man," declared Bart, "but it will be a cold day
when he lays alongside a wreck ahead of that daddy of mine."
The boys were busy with their unbeaten sloop Sombrero, and one
day slid into another while Dan employed much of his spare time in
helping his mother about the house and in painting the chicken-
house, the fences, and porch with great pride in the spick-and-span
results. Mrs. Frazier still professed to take no stock in the plot
hatched by "Barton's father and Mary Pringle's husband," but she
was nervous and absent-minded at times, and there was even more
affection than usual in her manner toward Bart.
Dan tacked a calendar at the head of his bed and crossed off the
days one by one, saying to himself when he awoke and looked at it:
"Twenty days out from London, as Uncle Jim figured it, and the
Kenilworth is one day nearer the Reef."
Twenty-two days had been counted when Captain Jim called at the
cottage and told Dan to go aboard the Resolute and stay there until
further orders. When the deck-hand reported for duty, he found all
hands of the crew either at work on board or within call on the
wharf. Bill McKnight had steam in his boilers and, although the fires
were banked, he had just finished stowing below a generous supply
of resinous pine wood, oil-soaked cotton waste, and a barrel of
turpentine for use as emergency fuel.
"I lost thirty-five pounds of weight in three weeks," snorted the
engineer, "but I mended the old hooker to stay mended. Ho, ho,
there goes the Henry Foster to sea, Captain. Wonder if there's
anything doing so soon? Her engines sound like a mowing-machine
trying to cut a path through a brick-yard."
"Don't worry about her," muttered Captain Jim. "Pringle isn't aboard
her. We won't leave here until he gets uneasy. He is a good deal
better posted than I am about his infernal program and we——"
Captain Jim stopped short, for Barton Pringle unexpectedly appeared
on deck and announced to Dan:
"I'm going up the Hawk Channel with father at daylight to look for
one of our sponging vessels that's reported ashore near Bahia
Honda Key. Thought I'd say good-by."
Dan could not help glancing at Captain Jim as he replied with a
quiver of excitement in his voice:
"We may be running up the outside channel before you get back,
Bart. Perhaps we shall sight you. Hope you have a good trip."
Barton was in a hurry and jumped ashore with a wave of his hand to
the chief engineer. When he was out of ear-shot Dan observed with
a long face:
"I would give six months' wages if I could make Bart stay home. Do
you suppose his father is really going to sea at daylight, or is he just
using Bart to fool us?"
"I haven't been walking in my sleep," dryly responded Captain Jim.
"There's a hundred and fifty miles of the Reef between here and
Miami and I don't intend to follow any decoy ducks and fetch up at
the wrong end of it. I figure on getting a report of any disaster as
soon as the next man."
The next day passed without tidings. Jeremiah Pringle had vanished
from his haunts in Key West, and four of his schooners were not to
be found at their moorings. Another day dragged by, Bill McKnight
was stewing with impatience and Dan Frazier was losing his appetite
while Captain Jim Wetherly remained cheerful and unruffled.
He was like another man, however, when a message came to him at
noon on the fourth day of waiting. It was from the cable office and
he had no more than glanced at it before he darted on deck,
ordered the mate to get the crew aboard, shouted down a speaking-
tube to Bill McKnight, and took his station at the wheel. His keen-
witted, masterful energy seemed to thrill the Resolute with life and
action. Black smoke gushed from her funnel as her stokers toiled in
front of the furnace doors. The engines were turning over when the
last deck-hand leaped aboard, and as the dripping hawsers were
hauled in, the tug was moving out into the stream.
Key West island was over her stern before Dan found time to run up
to the wheel-house. Captain Jim slipped a crumpled bit of paper into
his fist and motioned for him to keep it to himself. It was from the
marine observer at Jupiter Inlet, a hundred miles to the northward
of the Florida Reef:
"Steamer Kenilworth southbound passed seven this morning.
Signalled steering gear disabled by heavy weather but able to
proceed."
Dan's faith in human nature, as it had to do with the master of the
Kenilworth, had been so severely shocked that he wondered whether
the report of her mishap could be true. He was not shrewd enough
to perceive, however, what Captain Jim whispered as he went below
to see how things were moving in the engine-room.
"Crippled steering gear, bosh. Her skipper has to fake up some
excuse for striking the Reef."
Dan could scarcely believe that the curtain had really risen on this
seafaring melodrama in which he was to be an actor. A stately ship
was moving blindly toward an ambush which might be the death of
her. And racing to find and befriend her was this lone tug whose
throbbing heart of steel shook her stout hull from bow to stern as
she tore through the long head-seas on the edge of the Gulf Stream.
The afternoon was already waning and night would overtake the
Resolute before she could reach the upper stretches of the Reef.
Captain Wetherly felt certain that the Kenilworth would not be
rammed on the coral ledges in broad daylight, and he foresaw a
desperate game of hide-and-seek between darkness and dawn. But
he held to the doctrine that with anything like even chances an
honest man will win against a rascal in the game of life, afloat or
ashore.
The north-east wind was steadily freshening and the sky had
become gray with drifting clouds. As dusk crept over the uneasy sea
a mist-like rain began to drizzle. The master of the Kenilworth might
reasonably lose his bearings if the night grew much thicker. Bill
McKnight emerged from his sultry cavern long enough to grumble to
Dan:
"What's to hinder our running past that steamer before morning, I
want to know, hey, boy?"
"You wouldn't worry if you could watch Captain Jim hug the Reef,"
assured Dan. "It's like walking a tight-rope. I thought we were going
to climb right up into the American Shoal light-house."
"Well, this old tug is doing her fifteen knots, Dan, which is faster
than she ever flew before," chuckled the chief engineer, "and if we
touch bottom, you'll know it all right. Look up yonder at my
fireworks."
Dan stared at a banner of solid flame that streamed from the funnel
which glowed red hot for a dozen feet above the deck. With a cry of
alarm he ran to the upper deck-houses which were built just fore
and aft of the funnel and found the wood-work charred and
smoking. He shouted down to McKnight who replied with a laugh:
"It isn't my affair if your superstructure burns up. My orders are to
make steam. Better mention it to the skipper."
Dan rushed to the wheel-house but Captain Jim received the news
as if it were the merest trifle. He was sweeping the sea with his
night-glasses and exhorting the mate at the wheel to "hold her as
she is and keep your nerve." To Dan he replied airily:
"Caught afire, has she? Good for Bill McKnight. He's delivering the
goods. Get some men with buckets and put the fire out. I've no
steam to waste in starting the pumps and putting the hose on it."
The deck force was taking turns at shovelling coal to reinforce the
stifled stokers, and those off watch followed Dan with cheers. They
knew that a race was on, and it lightened their toil to know that the
Resolute was pounding toward her goal, wherever it was, with every
ounce of power in her. Captain Jim joined the fire-fighters long
enough to yell to them:
"Look out for rockets ahead. The first man to sight distress signals
from the Reef gets ten dollars and a new hat."
A brawny negro stoker wiped the sweat from his eyes as he bobbed
on deck and panted:
"When Cap'n Jim smell a wreck she's sure gwine be where he say. If
he wants to find 'stress signals he better look amongst us poor
niggers in the fire-room."
Midnight came and no one thought of sleep. The excitement had
spread even to the cook and the galley boy who thought they saw
rockets every time a match was lit up in the bows. Dan gazed out
into the starless night and listened to the clamor of the parting seas
alongside with frequent thoughts of Barton Pringle who was
somewhere out here, proud of his father's seamanship and daring,
loyal to his interests, trusting him as Dan trusted his Uncle Jim. Now
like pawns on a chess board, the two boys were to play their parts
on the opposing sides of a conflict which would be fought to the
bitter end. Dan was aroused by a hoarse shout from the bridge of
the Resolute:
"Red rocket two points off the port bow."
Dan wheeled and looked forward while his breath seemed to choke
him. A second rocket soared skyward, like a crimson thread hung
against the curtain of night.
"Hold her steady as she is," shouted Captain Jim from his post on
the bridge. "The weather has cleared a bit and that signal was a
long way off."
There was an exultant ring to his strong voice as if he were glad to
have the climax in sight. He sent for Dan and told him to stay on the
bridge and look for answering signals.
"It's the Kenilworth, a thousand to one," said the captain of the
Resolute. "And if Jerry Pringle's schemes haven't missed fire, his tug
or one of his schooners will just happen to be within signalling
distance. Ah, by Judas, there goes his answer, a rocket way out to
seaward. Pringle was afraid to hug the Reef on a thick night. He
missed the Kenilworth when she passed inside of him. It may
possibly be a merchantman that has seen the Kenilworth's signals,
but we take no chances."
Captain Wetherly shouted the tidings down the tube to the engine-
room force, and the hard-driven tug tore her way through the heavy
seas in the last gallant burst of the home-stretch. Back through the
speaking-tube bellowed the voice of the chief engineer:
"I've just put the clamp on the safety-valve, Captain. She's carrying
thirty pounds more steam than the law allows, and if she cracks
she'll crack wide open. Hooray! Give it to her!"
As if the captain of the stranded steamer were content to know that
his message had been seen and answered, he sent up no more
rockets, nor did any more answering signals gleam out to seaward.
It was a race in the dark. The Resolute and her rival, if such it was,
must run down two sides of a triangle whose apex was the unseen
vessel on the Reef. Captain Jim had taken the compass bearings of
the Kenilworth's rockets and, regardless of the risk he ran in driving
his steamer along the very fangs of the Reef, he held her in a
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!
ebookfinal.com

More Related Content

PDF
Introduction to Computing Systems From bits and gates to C and beyond 2nd Int...
PDF
Introduction To Computing Systems From Bits And Gates To C And Beyond 2nd Int...
PDF
Introduction to Computing Systems: From Bits & Gates to C & Beyond 3rd Editio...
PDF
Download full ebook of Computer Systems 5th Edition (eBook PDF) instant downl...
PDF
Computer Systems A Programmers Perspective 2nd Edition 2nd Edition Bryant
PPTX
.Comp Org and Arch All_Slide_1711695396000.pptx
PPTX
ICT FIRST LECTURE.pptx
PPTX
ComputerProgrammingCPattPatelChapter.pptx
Introduction to Computing Systems From bits and gates to C and beyond 2nd Int...
Introduction To Computing Systems From Bits And Gates To C And Beyond 2nd Int...
Introduction to Computing Systems: From Bits & Gates to C & Beyond 3rd Editio...
Download full ebook of Computer Systems 5th Edition (eBook PDF) instant downl...
Computer Systems A Programmers Perspective 2nd Edition 2nd Edition Bryant
.Comp Org and Arch All_Slide_1711695396000.pptx
ICT FIRST LECTURE.pptx
ComputerProgrammingCPattPatelChapter.pptx

Similar to Introduction to Computing Systems From bits and gates to C and beyond 2nd International Edition Yale Patt (20)

PPTX
Ch01.pptxxxxxxxxxcxcxcxxccxxxxxxxxxxxcccccc
PPTX
Ch01.pptxcomputer organization and architecture schools
PPT
Digital system design using vhdl and verilog
PDF
Computer Organization Basic Processor Structure Gil De Lamadrid
PPT
f37-book-intarch-pres-pt1.ppt
PPT
f37-book-intarch-pres-pt1.ppt
PPT
Chapter1.ppt
PPT
computer logic and digital design chapter 1
PPTX
ch01_inclass_computers_Chapter 1_Welcome Aboard.pptx
PPT
An Introduction to Computer Logic and Digital Design.ppt
PPT
Data Structure and AlgorithmChapter1.ppt
PPT
f37-book-intarch-pres-pt1.ppt
PDF
Csc 2313 (lecture 4)
PPT
Computer architecture
PPT
Computer architecture
PPTX
EE5440 – Computer Architecture - Lecture 1
PDF
Digital logic and microprocessors
PPSX
Coa presentation1
PPTX
F21-LOGIC DESIGN Advanced lec-FOE-CMPN111 SP23.pptx
Ch01.pptxxxxxxxxxcxcxcxxccxxxxxxxxxxxcccccc
Ch01.pptxcomputer organization and architecture schools
Digital system design using vhdl and verilog
Computer Organization Basic Processor Structure Gil De Lamadrid
f37-book-intarch-pres-pt1.ppt
f37-book-intarch-pres-pt1.ppt
Chapter1.ppt
computer logic and digital design chapter 1
ch01_inclass_computers_Chapter 1_Welcome Aboard.pptx
An Introduction to Computer Logic and Digital Design.ppt
Data Structure and AlgorithmChapter1.ppt
f37-book-intarch-pres-pt1.ppt
Csc 2313 (lecture 4)
Computer architecture
Computer architecture
EE5440 – Computer Architecture - Lecture 1
Digital logic and microprocessors
Coa presentation1
F21-LOGIC DESIGN Advanced lec-FOE-CMPN111 SP23.pptx
Ad

Recently uploaded (20)

PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PPTX
Computer Architecture Input Output Memory.pptx
PDF
Race Reva University – Shaping Future Leaders in Artificial Intelligence
PDF
Hazard Identification & Risk Assessment .pdf
PDF
International_Financial_Reporting_Standa.pdf
PDF
Journal of Dental Science - UDMY (2021).pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PPTX
Core Concepts of Personalized Learning and Virtual Learning Environments
PDF
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI .pdf
PDF
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
Complications of Minimal Access-Surgery.pdf
PDF
My India Quiz Book_20210205121199924.pdf
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
Computer Architecture Input Output Memory.pptx
Race Reva University – Shaping Future Leaders in Artificial Intelligence
Hazard Identification & Risk Assessment .pdf
International_Financial_Reporting_Standa.pdf
Journal of Dental Science - UDMY (2021).pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
Paper A Mock Exam 9_ Attempt review.pdf.
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
B.Sc. DS Unit 2 Software Engineering.pptx
Core Concepts of Personalized Learning and Virtual Learning Environments
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI .pdf
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
Environmental Education MCQ BD2EE - Share Source.pdf
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Unit 4 Computer Architecture Multicore Processor.pptx
Complications of Minimal Access-Surgery.pdf
My India Quiz Book_20210205121199924.pdf
Ad

Introduction to Computing Systems From bits and gates to C and beyond 2nd International Edition Yale Patt

  • 1. Introduction to Computing Systems From bits and gates to C and beyond 2nd International Edition Yale Patt pdf download https://ebookfinal.com/download/introduction-to-computing- systems-from-bits-and-gates-to-c-and-beyond-2nd-international- edition-yale-patt/ Explore and download more ebooks or textbooks at ebookfinal.com
  • 2. We have selected some products that you may be interested in Click the link to download now or visit ebookfinal.com for more options!. From Kosovo to Kabul and Beyond Human Rights and International Intervention David Chandler https://ebookfinal.com/download/from-kosovo-to-kabul-and-beyond-human- rights-and-international-intervention-david-chandler/ Introduction to Grid Computing 1st Edition Frederic Magoules https://ebookfinal.com/download/introduction-to-grid-computing-1st- edition-frederic-magoules/ Database Systems Introduction to Databases and Data Warehouses 2nd Edition Nenad Jukic■ https://ebookfinal.com/download/database-systems-introduction-to- databases-and-data-warehouses-2nd-edition-nenad-jukic/ Introduction to Optical Microscopy 2nd Edition Jerome C. Mertz https://ebookfinal.com/download/introduction-to-optical- microscopy-2nd-edition-jerome-c-mertz/
  • 3. Practicing Harm Reduction Psychotherapy An Alternative Approach to Addictions 2nd Edition Patt Denning https://ebookfinal.com/download/practicing-harm-reduction- psychotherapy-an-alternative-approach-to-addictions-2nd-edition-patt- denning/ Introduction to Building Procurement Systems 2nd Edition Dr Jack Masterman https://ebookfinal.com/download/introduction-to-building-procurement- systems-2nd-edition-dr-jack-masterman/ Introduction to High Performance Computing for Scientists and Engineers 1st Edition Georg Hager https://ebookfinal.com/download/introduction-to-high-performance- computing-for-scientists-and-engineers-1st-edition-georg-hager/ Stimuli Responsive Drug Delivery Systems From Introduction to Application 1st Edition Bajpai https://ebookfinal.com/download/stimuli-responsive-drug-delivery- systems-from-introduction-to-application-1st-edition-bajpai/ Structure and Function From clause to discourse and beyond Christopher Butler https://ebookfinal.com/download/structure-and-function-from-clause-to- discourse-and-beyond-christopher-butler/
  • 5. Introduction to Computing Systems From bits and gates to C and beyond 2nd International Edition Yale Patt Digital Instant Download Author(s): Yale Patt, Sanjay Patel ISBN(s): 9780071245012, 0071245014 Edition: 2nd International File Details: PDF, 13.10 MB Year: 2005 Language: english
  • 7. The McGraw-Hill Companies Mc Graw Hill INTRODUCTION TO COMPUTING SYSTEMS: FROM BITS AND GATES TO C AND BEYOND SECOND EDITION International Edition 2005 Exclusive rights by McGraw-Hill Education (Asia), for manufacture and export. This book cannot be re-exported from the country to which it is sold by McGraw-Hill. The International Edition is not available in North America. Published by McGraw-Hill, a business unit of The McGraw-Hill Companies, Inc., 1221 Avenue of the Americas, New York, NY 10020. Copyright © 2004, 2001 by The McGraw-Hill Companies, Inc. All rights reserved. No part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written consent of The McGraw- Hill Companies, Inc., including, but not limited to, in any network or other electronic storage or transmission, or broadcast for distance learning. Some ancillaries, including electronic and print components, may not be available to customers outside the United States. 10 09 08 07 06 05 04 03 02 01 20 09 08 07 06 05 04 CTF SEP Cover images: ©Photodisc, AA048376 Green Abstract, AA003317 Circuit Board Detail Library of Congress Control Number: 2003051002 When ordering this title, use ISBN 007-124501-4 Printed in Singapore
  • 8. > > second edition introduction to computing systems from bits and gates to C and beyond Yale N. Patt The University of Texas at Austin Sanjay J. Patel University of Illinois at Urbana-Champaign Mc Graw Hill Higher Education Boston Burr Ridge, IL Dubuque, IA Madison, Wl New York San Francisco St. Louis Bangkok Bogota Caracas Kuala Lumpur Lisbon London Madrid Mexico City Milan Montreal New Delhi Santiago Seoul Singapore Sydney Taipei Toronto
  • 9. To the memory of my parents, Abraham Walter Patt A"H and Sarah Clara Patt A"H, who taught me to value "learning" even before they taught me to ride a bicycle. To Mira and her grandparents, Sharda Patel and Jeram Patel.
  • 10. contents Preface xi Preface to the First Edition 1 Welcome Aboard 1 XVII 2.4.1 Binary to Decimal Conversion 27 2.4.2 Decimal to Binary Conversion 28 1.1 1.2 1.3 1.4 1.5 1.6 1.7 What We Will Try to Do 1 How We Will Get There 2 Two Recurring Themes 3 1.3.1 The Notion of Abstraction 3 1.3.2 Hardware versus Software 5 A Computer System 7 Two Very Important Ideas 9 Computers as Universal Computational Devices 9 How Do We Get the Electrons to Do the Work? 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 Exercises 17 12 The Statement of the Problem 13 The Algorithm 13 The Program 14 The ISA 14 The Microarchitecture 15 The Logic Circuit 16 The Devices 16 Putting It Together 16 2 Bits, Data Types, and Operations 21 2.1 2.2 2.3 2.4 Bits and Data Types 21 2.1.1 The Bit as the Unit of Information 21 2.1.2 Data Types 22 Integer Data Types 23 2.2.1 Unsigned Integers 23 2.2.2 Signed Integers 23 2's Complement Integers 25 Binary-Decimal ..Conversion 27 2.5 Operations on Bits—Part I: Arithmetic 2.5.1 Addition and Subtraction 29 2.5.2 Sign-Extension 30 2.5.3 Overflow 31 2.6 Operations on Bits—Part I I : Logical Operations 33 2.6.1 v The AND Function 33 2.6.2 The OR Function 34 2.6.3 The NOT Function 35 2.6.4 The Exclusive-OR Function 35 2.7 Other Representations 36 2.7.1 The Bit Vector 36 2.7.2 Floating Point Data Type 37 2.7.3 ASCII Codes 40 2.7.4 Hexadecimal Notation 41 Exercises 43 3 Digital Logic Structures 51 3.1 The Transistor 5 1 3.2 Logic Gates 53 3.2.1 The NOT Gate (Inverter) 53 3.2.2 OR and NOR Gates 54 3.2.3 AND and NAND Gates 56 3.2.4 DeMorgan's Law 58 3.2.5 Larger Gates 58 3.3 Combinational Logic Circuits 59 3.3.1 Decoder 59 3.3.2 Mux 60 3.3.3 Full Adder 61 3.3.4 The Programmable Logic Array (PLA) 63 3.3.5 Logical Completeness 64 Basic Storage Elements 64 3.4.1 The R-S Latch 64 3.4.2 The Gated D Latch 66 3.4.3 A Register 66 29 3.4
  • 11. vi Contents 3.5 The Concept of Memory 67 3.5.1 Address Space 68 3.5.2 Addressability 68 3.5.3 A 22 -by-3-Bit Memory 68 3.6 Sequential Logic Circuits 70 3.6.1 A Simple Example: The Combination Lock 71 3.6.2 The Concept of State 72 3.6.3 Finite State Machines 74 3.6.4 An Example: The Complete Implementation of a Finite State Machine 77 3.7 The Data Path of the LC-3 80 Exercises 82 5.4 Control Instructions 130 5.4.1 Conditional Branches 131 5.4.2 An Example 132 5.4.3 Two Methods for Loop Control 135 5.4.4 Example: Adding a Column of Numbers Using a Sentinel 135 5.4.5 The JMP Instruction 136 5.4.6 The TRAP Instruction 137 5.5 Another Example: Counting Occurrences of a Character 138 5.6 The Data Path Revisited 141 5.6.1 Basic Components of the Data Path 141 5.6.2 The Instruction Cycle 144 Exercises 145 4 The von Neumann Model 97 4.1 Basic Components 97 4.1.1 Memory 98 4.1.2 Processing Unit 99 4.1.3 Input and Output 100 4.1.4 Control Unit 100 4.2 The LC-3: An Example von Neumann Machine 101 4.3 Instruction Processing 103 4.3.1 The Instruction 103 4.3.2 The Instruction Cycle 104 4.4 Changing the Sequence of Execution 107 4.4.1 Control of the Instruction Cycle 108 4.5 Stopping the Computer 110 Exercises 111 6 Programming 155 6.1 Problem Solving 155 6.1.1 Systematic Decomposition 155 6.1.2 The Three Constructs: Sequential; Conditional, Iterative 156 6.1.3 LC-3 Control Instructions to Implement the Three Constructs 157 6.1.4 The Character Count Example from Chapter 5, Revisited 158 6.2 Debugging 162 6.2.1 Debugging Operations 163 6.2.2 Examples: Use of the Interactive Debugger 164 Exercises 172 5 The LC-3 115 5.1 The ISA: Overview 115 5.1.1 Memory Organization 116 5.1.2 Registers 116 5.1.3 The Instruction Set 117 5.1.4 Opcodes 117 5.1.5 Data Types 118 5.1.6 Addressing Modes 118 5.1.7 Condition Codes 120 5.2 Operate Instructions 120 5.3 Data Movement Instructions 123 5.3.1 PC-Relative Mode 124 5.3.2 Indirect Mode 125 5.3.3 Base+offset Mode 127 5.3.4 Immediate Mode 128 5.3.5 An Example 129 7 Assembly Language 177 7.1 Assembly Language Programming — Moving Up a Level 177 7.2 An Assembly Language Program 178 7.2.1 Instructions 179 7.2.2 Pseudo-ops (Assembler Directives) 182 7.2.3 Example: The Character Count Example of Section 5.5, Revisited 183 7.3 The Assembly Process 185 7.3.1 Introduction 185 7.3.2 A Two-Pass Process 185 7.3.3 The First Pass: Creating the Symbol Table 186 7.3.4 The Second Pass: Generating the Machine Language Program 187
  • 12. Contents vii 7.4 Beyond the Assembly of a Single Assembly Language Program 188 7.4.1 The Executable Image 189 7.4.2 More than One Object File 189 Exercises 190 8 I/O 199 8.1 I/O Basics 199 8.1.1 Device Registers 199 8.1.2 Memory-Mapped I/O versus Special Input/Output Instructions 200 8.1.3 Asynchronous versus Synchronous 200 8.1.4 Interrupt-Driven versus Polling 202 8.2 Input from the Keyboard 202 8.2.1 Basic Input Registers (the KBDR and the KBSR) 202 8.2.2 The Basic Input Service Routine 202 8.2.3 Implementation of Memory-Mapped Input 203 8.3 Output to the Monitor 204 8.3.1 Basic Output Registers (the DDR and the DSR) 204 8.3.2 The Basic Output Service Routine 205 8.3.3 Implementation of Memory-Mapped Output 206 8.3.4 Example: Keyboard Echo 207 8.4 A More Sophisticated Input Routine 207 8.5 Interrupt-Driven I/O 209 8.5.1 What Is Interrupt-Driven I/O? 209 8.5.2 Why Have Interrupt-Driven I/O? 210 8.5.3 Generation of the Interrupt Signal 211 8.6 Implementation of Memory-Mapped 1/0/ Revisited 214 Exercises 215 9.1.5 TRAP Routines for Handling I/O 225 9.1.6 TRAP Routine for Halting the Computer 225 9.1.7 Saving and Restoring Registers 229 9.2 Subroutines 230 9.2.1 The Call/Return Mechanism 230 9.2.2 The JSR(R) Instruction 232 9.2.3 The TRAP Routine for Character Input, Revisited 233 9.2.4 PUTS: Writing a Character String to the Monitor 235 9.2.5 Library Routines 235 Exercises 240 10 And, Finally . . . The Stack 251 10.1 The Stack: Its Basic Structure 251 10.1.1 The S t a c k - A n Abstract Data Type 251 10.1.2 Two Example Implementations 252 10.1.3 Implementation in Memory 253 10.1.4 The Complete Picture 257 10.2 Interrupt-Driven I/O (Part 2) 258 10.2.1 Initiate and Service the Interrupt 259 10.2.2 Return from the Interrupt 261 10.2.3 An Example 262 10.3 Arithmetic Using a Stack 264 10.3.1 The Stack as Temporary Storage 264 10.3.2 An Example 265 10.3.3 OpAdd, Op Mult, and OpNeg 265 10.4 Data Type Conversion 272 10.4.1 Example: The Bogus Program: 2 + 3 = e 272 10.4.2 ASCII to Binary 273 10.4.3 Binary to ASCII 276 10.5 Our Final Example: The Calculator 278 Exercises 283 9 TRAP Routines and Subroutines 219 9.1 LC-3 TRAP Routines 219 9.1.1 Introduction 219 9.1.2 The TRAP Mechanism 220 9.1.3 The TRAP Instruction 221 9.1.4 The Complete Mechanism 222 11 Introduction to Programming inC 289 11.1 Our Objective 289 11.2 Bridging the Gap 290 11.3 Translating High-Level Language Programs 292
  • 13. viii Contents 11.3.1 Interpretation 292 11.3.2 Compilation 293 11.3.3 Pros and Cons 293 11.4 The C Programming Language 293 11.4.1 The C Compiler 295 11.5 A Simple Example 297 11.5.1 The Function m a i n 297 11.5.2 Formatting, Comments, and Style 299 11.5.3 The C Preprocessor 300 11.5.4 Input and Output 3 0 1 11.6 Summary 3 0 4 Exercises 3 0 5 12 Variables and Operators 307 1 2 . 1 Introduction 3 0 7 12.2 Variables 3 0 8 12.2.1 Three Basic Data Types: int, char, d o u b l e 308 12.2.2 Choosing Identifiers 310 12.2.3 Scope: Local versus Global 3 1 1 12.2.4 More Examples 313 12.3 Operators 3 1 4 12.3.1 Expressions and Statements 315 12.3.2 The Assignment Operator 316 12.3.3 Arithmetic Operators 317 12.3.4 Order of Evaluation 318 12.3.5 Bitwise Operators 319 12.3.6 Relational Operators 320 12.3.7 Logical Operators 322 12.3.8 Increment/Decrement Operators 322 12.3.9 Expressions with Multiple Operators 324 12.4 Problem Solving Using Operators 3 2 4 12.5 Tying it All Together 3 2 6 12.5.1 Symbol Table 326 12.5.2 Allocating Space for Variables 328 12.5.3 A Comprehensive Example 331 12.6 Additional Topics 332 12.6.1 Variations of the Three Basic Types 332 12.6.2 Literals, Constants, and Symbolic Values 334 12.6.3 Storage Class 335 12.6.4 Additional C Operators 336 12.7 Summary 337 Exercises 3 3 8 13 Control Structures 343 1 3 . 1 Introduction 3 4 3 13.2 Conditional Constructs 3 4 4 13.2.1 The if Statement 344 13.2.2 The if-else Statement 347 13.3 Iteration Constructs 3 5 0 13.3.1 The while Statement 350 13.3.2 The for Statement 353 13.3.3 The do-while Statement 358 13.4 Problem Solving Using Control Structures 3 5 9 13.4.1 Problem 1: Approximating the Value of 7i 360 13.4.2 Problem 2: Finding Prime Numbers Less than 100 362 13.4.3 Problem 3: Analyzing an E-mail Address 366 13.5 Additional C Control Structures 3 6 8 13.5.1 The switch Statement 368 13.5.2 The break and continue Statements 370 13.5.3 An Example: Simple Calculator 370 13.6 Summary 372 Exercises 372 14 Functions 379 1 4 . 1 Introduction 3 7 9 14.2 Functions in C 3 8 0 14.2.1 A Function with a Parameter 380 14.2.2 Example: Area of a Ring 384 14.3 Implementing Functions in C 3 8 5 14.3.1 Run-Time Stack 385 14.3.2 Getting It All to Work 388 14.3.3 Tying It All Together 393 14.4 Problem Solving Using Functions 3 9 4 14.4.1 Problem 1: Case Conversion 395 14.4.2 Problem 2: Pythagorean Triples 397 14.5 Summary 3 9 8 Exercises 3 9 9 15 Testing and Debugging 407 1 5 . 1 Introduction 4 0 7 15.2 Types of Errors 4 0 8 15.2.1 Syntactic Errors 409
  • 14. Contents ix 15.2.2 Semantic Errors 409 15.2.3 Algorithmic Errors 411 15.3 Testing 412 15.3.1 Black-Box Testing 412 15.3.2 White-Box Testing 413 15.4 Debugging 414 15.4.1 Ad Hoc Techniques 414 15.4.2 Source-Level Debuggers 415 15.5 Programming for Correctness 417 15.5.1 Nailing Down the Specification 417 15.5.2 Modular Design 418 15.5.3 Defensive Programming 418 15.6 Summary 419 Exercises 4 2 1 16 Pointers and Arrays 427 16.1 Introduction 427 16.2 Pointers 428 16.2.1 Declaring Pointer Variables 429 16.2.2 Pointer Operators 430 16.2.3 Passing a Reference Using Pointers 432 16.2.4 Null Pointers 433 16.2.5 Demystifying the Syntax 434 16.2.6 An Example Problem Involving Pointers 434 16.3 Arrays 436 16.3.1 Declaring and Using Arrays 436 16.3.2 Examples Using Arrays 438 16.3.3 Arrays as Parameters 440 16.3.4 Strings in C 441 16.3.5 The Relationship Between Arrays and Pointers in C 446 16.3.6 Problem Solving: Insertion Sort 446 16.3.7 Common Pitfalls with Arrays in C 449 16.4 Summary 4 5 1 Exercises 4 5 1 17 Recursion 457 17.1 Introduction 457 17.2 What Is Recursion? 458 17.3 Recursion versus Iteration 459 17.4 Towers of Hanoi 460 17.5 Fibonacci Numbers 464 17.6 Binary Search 468 17.7 Integer to A S C I I 4 7 1 17.8 Summary 473 Exercises 473 18 I/O in C 481 18.1 Introduction 4 8 1 18.2 The C Standard Library 4 8 1 18.3 I/O, One Character at a Time 482 18.3.1 I/O Streams 482 18.3.2 p u t c h a r 483 18.3.3 g e t c h a r 483 18.3.4 Buffered I/O 483 18.4 Formatted I/O 485 18.4.1 p r i n t f 485 18.4.2 s c a n f 487 18.4.3 Variable Argument Lists 489 18.5 I/O from Files 4 9 1 18.6 Summary 493 Exercises 494 19 Data Structures 497 19.1 Introduction 497 19.2 Structures 498 19.2.1 typedef 500 19.2.2 Implementing Structures in C 501 19.3 Arrays of Structures 502 19.4 Dynamic Memory Allocation 504 19.4.1 Dynamically Sized Arrays 506 19.5 Linked Lists 508 19.5.1 An Example 510 19.6 Summary 516 Exercises 517 A The LC-3 ISA 521 A . l Overview 5 2 1 A.2 Notation 523 A.3 The Instruction Set 523 A.4 Interrupt and Exception Processing 543 A.4.1 Interrupts 543 A.4.2 Exceptions 544
  • 15. X Contents B From LC-3 to x86 547 B . l LC-3 Features and Corresponding x86 Features 548 B . l . l Instruction Set 548 B.l.2 Memory 553 B.l.3 Internal State 553 B.2 The Format and Specification of x86 Instructions 557 B.2.1 Prefix 558 B.2.2 Opcode 559 B.2.3 ModR/M Byte 559 B.2.4 SIB Byte 560 B.2.5 Displacement 560 B.2.6 Immediate 560 B.3 An Example 562 C The Microarchitecture of the LC-3 565 C . l Overview 565 C.2 The State Machine 567 C.3 The Data Path 569 C.4 The Control Structure 569 C.5 Memory-Mapped I/O 575 C.6 Interrupt and Exception Control 576 C.6.1 Initiating an Interrupt 579 C.6.2 Returning from an Interrupt, RTI 581 C.6.3 The Illegal Opcode Exception 582 C.7 Control Store 583 D The C Programming Language 585 D . l Overview 585 D.2 C Conventions 585 D.2.1 Source Files 585 D.2.2 Header Files 585 D.2.3 Comments 586 D.2.4 Literals 586 D.2.5 Formatting 588 D.2.6 Keywords 588 D.3 Types 589 D.3.1 Basic Data Types 589 D.3.2 Type Qualifiers 590 D.3.3 Storage Class 591 D.3.4 Derived Types 592 D.3.5 typedef 594 D.4 Declarations 595 D.4.1 Variable Declarations 595 D.4.2 Function Declarations 596 D.5 Operators 596 D.5.1 Assignment Operators 597 Arithmetic Operators 597 Bit-wise Operators 598 Logical Operators 598 Relational Operators 599 I ncrement/Decrement Operators 599 Conditional Expression 600 Pointer, Array, and Structure Operators 600 sizeof 601 Order of Evaluation 602 Type Conversions 602 Expressions and Statements 603 D.6.1 Expressions 603 Statements 604 604 I f 604 If-else 605 Switch 605 While 606 For 607 Do-while 607 Break 608 continue 608 return 609 D.8 The C Preprocessor 609 D.8.1 Macro substitution 609 D.8.2 File inclusion 610 D.9 Some Standard Library Functions 610 D.9.1 I/O Functions 611 D.9.2 String Functions 612 D.9.3 Math Functions 613 D.9.4 Utility Functions 613 D.6 D.7 D.5.2 D.5.3 D.5.4 D.5.5 D.5.6 D.5.7 D.5.8 D.5.9 D.5.10 D.5.11 D.6.2 Control D.7.1 D.7.2 D.7.3 D.7.4 D.7.5 D.7.6 D.7.7 D.7.8 D.7.9 E Useful Tables 615 E . l Commonly Used Numerical Prefixes E.2 Standard A S C I I codes 616 E.3 Powers of 2 617 F Solutions to Selected Exercises 619 615
  • 16. preface It is a pleasure to be writing a preface to the second edition of this book. Three years have passed since the first edition came out. We have received an enormous number of comments from students who have studied the material in the book and from instructors who have taught from it. Almost all have been very positive. It is gratifying to know that a lot of people agree with our approach, and that this agreement is based on real firsthand experience learning from it (in the case of students) or watching students learn from it (in the case of instructors). The excitement displayed in their e-mail continues to be a high for us. However, as we said in the preface to the first edition, this book will always be a "work in progress." Along with the accolades, we have received some good advice on how to make itbetter. We thank you for that. We have also each taught the course two more times since the first edition came out, and that, too, has improved our insights into what we think we did right and what needed improvement. The result has been a lot of changes in the second edition, while hopefully maintaining the essence of what we had before. How well we have succeeded we hope to soon learn from you. Major Changes to [lie First Edition The LC-3 One of the more obvious changes in the second edition is the replacement of the LC-2 with the LC-3. We insisted on keeping the basic concept of the LC-2: a rich ISA that can be described in a few pages, and hopefully mastered in a short time. We kept the 16-bit instruction and 4-bit opcode. One of our students pointed out that the subroutine return instruction (RET) was just a special case of LC-2's JMPR instruction, so we eliminated RET as a separate opcode. The LC-3 specifies only 15 opcodes—and leaves one for future use (perhaps, the third edition!). We received a lot of push-back on the PC-concatenate addressing mode, particularly for branches. The addressing mode had its roots in the old PDP-8 of the mid-1960s. A majorproblem with it comes up when an instruction on one page wants to dereference the next (or previous) page. This has been a major hassle, particularly for forward branches close to a page boundary. A lot of people have asked us to use the more modern PC+offset, and we agreed. We have replaced all uses of PC'offset with PC+SEXT(offset). We incorporated other changes in the LC-3. Stacks now grow toward 0, in keeping with current conventional practice. The offset in LDR/STR is now
  • 17. xii preface a signed value, so addresses can be computed plus or minus a base address. The opcode 1101 is not specified. The JSR/JMP opcodes have been reorganized slightly. Finally, we expanded the condition codes to a 16-bit processor status register (PSR) that includes a privilege mode and a priority level. As in the first edition, Appendix A specifies the LC-3 completely. Additional Material Although no chapter in the book has remained untouched, some chapters have been changed more than others. We added discussions to Chapter 1 on the nature and importance of abstraction and the interplay of hardware and software because it became clear that these points needed to be made explicit. We added a full section to Chapter 3 on finite state control and its implementation as a sequential switching circuit because we believe the concept of state and finite state control are among the most important concepts a computer science or engineering student encounters. We feel it is also useful to the understanding of the von Neumann model of execution discussed in Chapter 4. We added a section to Chapter 4 giving a glimpse of the underlying microarchitecture of the LC-3, which is spelled out in all its detail in the overhauled Appendix C. We were told by more than one reader that Chapter 5 was too terse. We added little new material, but lots of figures and explanations that hopefully make the concepts clearer. We also added major new sections on interrupt-driven I/O to Chapters 8 and 10. Just as in the first edition, Chapters 11 through 14 introduce the C program- ming language. Unlike the first edition, these chapters are more focused on the essential aspects of the language useful to a beginning programmer. Special- ized features, for example the C switch construct, are relegated to the ends of the chapters (or to Appendix D), out of the main line of the text. All of these chapters include more examples than the first edition. The second edition also places a heavier emphasis on "how to program" via problem-solving examples that demonstrate how newly introduced C constructs can be used in C program- ming. In Chapter 14, students are exposed to a new LC-3 calling convention that more closely reflects the calling convention used by real systems. Chapter 15 contains a deeper treatment of testing and debugging. Based on our experiences teaching the introductory course, we have decided to swap the order of the chapter on recursion with the chapter on pointers and arrays. Moving recursion later (now Chapter 17) in the order of treatment allows students to gain more experience with basic programming concepts before they start programming recursive functions. The Simulator Brian Hartman has updated the simulator that runs on Windows to incorporate the changes to the LC-3. Ashley Wise has written an LC-3 simulator that runs on UNIX. Both have incorporated interrupt-driven I/O into the simulator's function- ality. We believe strongly that there is no substitute for hands-on practice testing one's knowledge. With the addition of interrupt-driven I/O to the simulator, the student can now interrupt an executing program by typing a key on the keyboard and invoke an interrupt service routine.
  • 18. preface xiii Alternate Uses of the Booh We wrote the book as a textbook for a freshman introduction to computing. We strongly believe, as stated more completely in the preface to our first edition, that our motivated bottom-up approach is the best way for students to learn the fundamentals of computing. We have seen lots of evidence that suggests that in general, students who understand the fundamentals of how the computer works are better able to grasp the stuff that they encounter later, including the high-level programming languages that they must work in, and that they can learn the rules of these programming languages with far less memorizing because everything makes sense. For us, the best use of the book is a one-semester freshman course for particularly motivated students, or a two-semester sequence where the pace is tempered. If you choose to go the route of a one-semester course heavy on high-level language programming, you probably want to leave Out the material on sequential machines and interrupt-driven I/O. If you choose to go the one- semester route heavy on the first half of the book, you probably want to leave out much of Chapters 15, 17, 18, and 19. We have also seen the book used effectively in each of the following environments: Two Quarters, Freshman Course In some sense this is the best use of the book. In the first quarter, Chapters 1 through 10 are covered; in the second quarter, Chapters 11 through 19. The pace is brisk, but the entire book can be covered in two academic quarters. One-Semester Second Course The book has been used successfully as a second course in computing, after the student has spent the first course with a high-level programming language. The rationale is that after exposure to high-level language programming in the first course, the second course should treat at an introductory level digital logic, basic computer organization, and assembly language programming. Most of the semester is spent on Chapters 1 through 10, with the last few weeks spent on a few topics from Chapters 11 through 19, showing how some of the magic from the students' first course can actually be implemented. Functions, activation records, recursion, pointer variables, and some elementary data structures are typically the topics that get covered. A Sophomore-Level Computer Organization Course The book has been used to delve deeply into computer implementation in the sophomore year. The semester is spent in Chapters 1 through 10, sometimes culminating in a thorough study of Appendix C, which provides the complete microarchitecture of a microprogrammed LC-3. We note, however, that some very important ideas in computer architecture are not covered here, most notably cache memory, pipelining, and virtual memory. We agree that these topics are very important to the education of a computer scientist or computer engineer, but we feel these topics are better suited to a senior course in computer architecture and design. This book is not intended for that purpose.
  • 19. xhr preface Acknowledgments Our book continues to benefit greatly from important contributions of many, many people. We particularly want to acknowledge Brian Hartman and Matt Starolis. Brian Hartman continues to be a very important part of this work, both for the great positive energy he brings to the table and for his technical expertise. He is now out of school more than three years and remains committed to the concept. He took the course the first year it was offered at Michigan (Winter term, 1996), TAed it several times as an undergraduate student, and wrote the first LC-2 simulator for Windows while he was working on his master's degree. He recently upgraded the Windows simulator to incorporate the new LC-3. Matt Starolis took the freshman course at UT two years ago and TAed it as a junior last fall. He, too, has been very important to us getting out this second edition. He has been both critic of our writing and helpful designer of many of the figures. He also updated the tutorials for the simulators, which was necessary in order to incorporate the new characteristics of the LC-3. When something needed to be done, Matt volunteered to do it. His enthusiasm for the course and the book has been a pleasure. With more than 100 adopters now, we regularly get enthusiastic e-mail with suggestions from professors from all over the world. Although we realize we have undoubtedly forgotten some, we would at least like to thank Professors Vijay Pai, Rice; Richard Johnson, Western New Mexico; Tore Larsen, Tromso; Greg Byrd, NC State; Walid Najjar, UC Riverside; Sean Joyce, Heidelberg Col- lege; James Boettler, South Carolina State; Steven Zeltmann, Arkansas; Mike McGregor, Alberta; David Lilja, Minnesota; Eric Thompson, Colorado, Denver; and Brad Hutchings, Brigham Young. Between the two of us, we have taught the course four more times since the first edition came out, and that has produced a new enthusiastic group of believ- ers, both TAs and students. Kathy Buckheit, Mustafa Erwa, Joseph Grzywacz, Chandresh Jain, Kevin Major, Onur Mutlu, Moinuddin Qureshi, Kapil Sachdeva, Russell Schreiber, Paroma Sen, Santhosh Srinath, Kameswar Subramaniam, David Thompson, Francis Tseng, Brian Ward, and Kevin Woley have all served as TAs and have demonstrated a commitment to helping students learn that can only be described as wonderful. Linda Bigelow, Matt Starolis, and Lester Guillory all took the course as freshmen, and two years later they were among the most enthusiastic TAs the course has known. Ashley Wise developed the Linux version of the LC-3 simulator. Ajay Ladsaria ported the LCC compiler to generate LC-3 code. Gregory Muthler and Francesco Spadini enthusiastically provided critical feedback on drafts of the chapters in the second half. Brian Fahs provided solutions to the exercises. Kathy Buckheit wrote introductory tutorials to help students use the LC-2 simulator because she felt it was necessary. Several other faculty members at The University of Texas have used the book and shared their insights with us: Tony Ambler, Craig Chase, Mario Gonzalez, and Earl Swartzlander in ECE, and Doug Burger, Chris Edmundson, and Steve Keckler in CS. We thank them.
  • 20. preface xv We continue to celebrate the commitment displayed by our editors, Betsy Jones and Michelle Flomenhoft. As was the case with the first edition, our book has benefited from exten- sive reviews provided by faculty members from many universities. We thank Robert Crisp, Arkansas; Allen Tannenbaum, Georgia Tech; Nickolas Jovanovic, Arkansas-Little Rock; Dean Brock, North Carolina-Asheville; Amar Raheja, Cal State-Pomona; Dayton Clark, Brooklyn College; William Yurcik, Illinois State; Jose Delgado-Frias, Washington State; Peter Drexel, Plymouth State; Mahmoud Manzoul, Jackson State; Dan Connors, Colorado; Massoud Ghyam, Southern Cal; John Gray, UMass-Dartmouth; John Hamilton, Auburn; Alan Rosenthal, Toronto; and Ron Taylor, Wright State. Finally, there are those who have contributed in many different and often unique ways. Without listing their individual contributions, we simply list them and say thank you. Amanda, Bryan, and Carissa Hwu, Mateo Valero, Rich Belgard, Janak Patel, Matthew Frank, Milena Milenkovic, Lila Rhoades, Bruce Shriver, Steve Lumetta, and Brian Evans. Sanjay would like to thank Ann Yeung for all her love and support. f) Final Word It is worth repeating our final words from the preface to the first edition: We are mindful that the current version of this book will always be a work in progress, and we welcome your comments on any aspect of it. You can reach us by e-mail at patt@ece.utexas.edu and sjp@crhc.uiuc.edu. We hope you will. Yale N. Patt Sanjay J. Patel May, 2003
  • 21. preface to the first edition This textbook has evolved from EECS 100, the first computing course for com- puter science, computer engineering, and electrical engineering majors at the University of Michigan, that Kevin Compton and the first author introduced for the first time in the fall term, 1995. EECS 100 happened because Computer Science and Engineering faculty had been dissatisfied for many years with the lack of student comprehension of some very basic concepts. For example, students had a lot of trouble with pointer variables. Recursion seemed to be "magic," beyond understanding. We decided in 1993 that the conventional wisdom of starting with a high- level programming language, which was the way we (and most universities) were doing it, had its shortcomings. We decided that the reason students were not getting it was that they were forced to memorize technical details when they did not understand the basic underpinnings. The result is the bottom-up approach taken in this book. We treat (in order) MOS transistors (very briefly, long enough for students to grasp their global switch-level behavior), logic gates, latches, logic structures (MUX, Decoder, Adder, gated latches), finally culminating in an implementation of memory. From there, we move on to the Von Neumann model of execution, then a simple com- puter (the LC-2), machine language programming of the LC-2, assembly language programming of the LC-2, the high level language C, recursion, pointers, arrays, and finally some elementary data structures. We do not endorse today's popular information hiding approach when it comes to learning. Information hiding is a useful productivity enhancement tech- nique after one understands what is going on. But until one gets to that point, we insist that information hiding gets in the way of understanding. Thus, we contin- ually build on what has gone before, so that nothing is magic, and everything can be tied to the foundation that has already been laid. We should point out that we do not disagree with the notion of top-down design. On the contrary, we believe strongly that top-down design is correct design. But there is a clear difference between how one approaches a design problem (after one understands the underlying building blocks), and what it takes to get to the point where one does understand the building blocks. In short, we believe in top-down design, but bottom-up learning for understanding.
  • 22. Htiaf Is in the Booh The book breaks down into two major segments, a) the underlying structure of a computer, as manifested in the LC-2; and b) programming in ahigh level language, in our case C. The LC-2 We start with the underpinnings that are needed to understand the workings of a real computer. Chapter 2 introduces the bit and arithmetic and logical operations on bits, Then we begin to build the structure needed to understand the LC-2. Chapter 3 takes the student from a MOS transistor, step by step, to a real memory. Our real memory consists of 4 words of 3 bits each, rather than 64 megabytes. The picture fits on a single page (Figure 3.20), making it easy for a student to grasp. By the time the students get there, they have been exposed to all the elements that make memory work. Chapter 4 introduces the Von Neumann execution model, as a lead-in to Chapter 5, the LC-2. The LC-2 is a 16-bit architecture that includes physical I/O via keyboard and monitor; TRAPs to the operating system for handling service calls; conditional branches on N, Z, and P condition codes; a subroutine call/return mechanism; a minimal set of operate instructions (ADD, AND, and NOT); and various address- ing modes for loads and stores (direct, indirect, Base+offset, and an immediate mode for loading effective addresses). Chapter 6 is devoted to programming methodology (stepwise refinement) and debugging, and Chapter 7 is an introduction to assembly language programming. We have developed a simulator and an assembler for the LC-2. Actually, we have developed two simulators, one that runs on Windows platforms and one that runs on UNIX. The Windows simulator is available on the website and on the CD- ROM. Students who would rather use the UNIX version can download and install the software from the web at no charge. Students use the simulator to test and debug programs written in LC-2 machine language and in LC-2 assembly language. The simulator allows online debugging (deposit, examine, single-step, set breakpoint, and so on). The sim- ulator can be used for simple LC-2 machine language and assembly language programming assignments, which are essential for students to master the concepts presented throughout the first 10 chapters. Assembly language is taught, but not to train expert assembly language pro- grammers. Indeed, if the purpose was to train assembly language programmers, the material would be presented in an upper-level course, not in an introductory course for freshmen. Rather, the material is presented in Chapter 7 because it is consistent with the paradigm of the book. In our bottom-up approach, by the time the student reaches Chapter 7, he/she can handle the process of transform- ing assembly language programs to sequences of 0s and Is. We go through the process of assembly step-by-step for a very simple LC-2 Assembler. By hand assembling, the student (at a very small additional cost in time) reinforces the important fundamental concept of translation. It is also the case that assembly language provides a user-friendly notation to describe machine instructions, something that is particularly useful for the
  • 23. xxii preface to the first edition second half of the book. Starting in Chapter 11, when we teach the semantics of C statements, it is far easier for the reader to deal with ADD Rl, R2, R3 than with 0001001010000011. Chapter 8 deals with physical input (from a keyboard) and output (to a mon- itor). Chapter 9 deals with TRAPs to the operating system, and subroutine calls and returns. Students study the operating system routines (written in LC-2 code) for carrying out physical I/O invoked by the TRAP instruction. The first half of the book concludes with Chapter 10, a treatment of stacks and data conversion at the LC-2 level, and a comprehensive example that makes use of both. The example is the simulation of a calculator, which is implemented by a main program and 11 subroutines. The Language C From there, we move on to C. The C programming language occupies the second half of the book. By the time the student gets to C, he/she has an understanding of the layers below. The C programming language fits very nicely with our bottom-up approach. Its low-level nature allows students to see clearly the connection between software and the underlying hardware. In this book we focus on basic concepts such as control structures, functions, and arrays. Once basic programming concepts are mastered, it is a short step for students to learn more advanced concepts such as objects and abstraction. Each time a new construct in C is introduced, the student is shown the LC-2 code that a compiler would produce. We cover the basic constructs of C (vari- ables, operators, control, and functions), pointers, recursion, arrays, structures, I/O, complex data structures, and dynamic allocation. Chapter 11 is a gentle introduction to high-level programming languages. At this point, students have dealt heavily with assembly language and can understand the motivation behind what high-level programming languages provide. Chapter 11 also contains a simple C program, which we use to kick-start the process of learning C. Chapter 12 deals with values, variables, constants, and operators. Chapter 13 introduces C control structures. We provide many complete program examples to give students a sample of how each of these concepts is used in practice. LC-2 code is used to demonstrate how each C construct affects the machine at the lower levels. In Chapter 14, students are exposed to techniques for debugging high-level source code. Chapter 15 introduces functions in C. Students are not merely exposed to the syntax of functions. Rather they learn how functions are actually executed using a run-time stack. A number of examples are provided. Chapter 16 teaches recursion, using the student's newly gained knowledge of functions, activation records, and the run-time stack. Chapter 17 teaches pointers and arrays, relying heavily on the student's understanding of how memory is organized. Chapter 18 introduces the details of I/O functions in C, in particular,
  • 24. xxii preface to the first edition streams, variable length argument lists, and how C I/O is affected by the various format specifications. This chapter relies on the student's earlier exposure to physical I/O in Chapter 8. Chapter 19 concludes the coverage of C with structures, dynamic memory allocation, and linked lists. Along the way, we have tried to emphasize good programming style and coding methodology by means of examples. Novice programmers probably learn at least as much from the programming examples they read as from the rules they are forced to study. Insights that accompany these examples are highlighted by means of lightbulb icons that are included in the margins. We have found that the concept of pointer variables (Chapter 17) is not at all a problem. By the time students encounter it, they have a good understanding of what memory is all about, since they have analyzed the logic design of a small memory (Chapter 3). They know the difference, for example, between a memory location's address and the data stored there. Recursion ceases to be magic since, by the time a student gets to that point (Chapter 16), he/she has already encountered all the underpinnings. Students understand how stacks work at the machine level (Chapter 10), and they under- stand the call/return mechanism from their LC-2 machine language programming experience, and the need for linkages between a called program and the return to the caller (Chapter 9). From this foundation, it is not a large step to explain func- tions by introducing run-time activation records (Chapter 15), with a lot of the mystery about argument passing, dynamic declarations, and so on, going away. Since a function can call a function, it is one additional small step (certainly no magic involved) for a function to call itself. Horn to Use This Booh We have discovered over the past two years that there are many ways the material in this book can be presented in class effectively. We suggest six presentations below: 1. The Michigan model. First course, no formal prerequisites. Very intensive, this course covers the entire book. We have found that with talented, very highly motivated students, this works best. 2. Normal usage. First course, no prerequisites. This course is also intensive, although less so. It covers most of the book, leaving out Sections 10.3 and 10.4 of Chapter 10, Chapters 16 (recursion), 18 (the details of C I/O), and 19 (data structures). 3. Second course. Several schools have successfully used the book in their second course, after the students have been exposed to programming with an object-oriented programming language in a milder first course. In this second course, the entire book is covered, spending the first two-thirds of the semester on the first 10 chapters, and the last one-third of the semester on the second half of the book. The second half of the book can move more quickly, given that it follows both Chapters 1-10 and the
  • 25. preface to the first edition xxi introductory programming course, which the student has already taken. Since students have experience with programming, lengthier programming projects can be assigned. This model allows students who were introduced to programming via an object-oriented language to pick up C, which they will certainly need if they plan to go on to advanced software courses such as operating systems. 4. Two quarters. An excellent use of the book. No prerequisites, the entire book can be covered easily in two quarters, the first quarter for Chapters 1-10, the second quarter fcr Chapters 11-19. 5. Two semesters. Perhaps the optimal use of the book. A two-semester sequence for freshmen. No formal prerequisites. First semester, Chapters 1-10, with supplemental material from Appendix C, the Microarchitecture of the LC-2. Second semester, Chapters 11-19 with additional substantial programming projects so that the students can solidify the concepts they learn in lectures. 6. A sophomore course in computer hardware. Some universities have found the book useful for a sophomore level breadth-first survey of computer hardware. They wish to introduce students in one semester to number systems, digital logic, computer organization, machine language and assembly language programming, finishing up with the material on stacks, activation records, recursion, and linked lists. The idea is to tie the hardware knowledge the students have acquired in the first part of the course to some of the harder to understand concepts that they struggled with in their freshman programming course. We strongly believe the better paradigm is to study the material in this book before tackling an object-oriented language. Nonetheless, we have seen this approach used successfully, where the sophomore student gets to understand the concepts in this course, after struggling with them during the freshman year. Some Observations Understanding, Not Memorizing Since the course builds from the bottom up, we have found that less memorization of seemingly arbitary rules is required than in traditional programming courses. Students understand that the rules make sense since by the time a topic is taught, they have an awareness of how that topic is implemented at the levels below it. This approach is good preparation for later courses in design, where understanding of and insights gained from fundamental underpinnings are essential to making the required design tradeoffs. The Student Debugs the Student's Program We hear complaints from industry all the time about CS graduates not being able to program. Part of the problem is the helpful teaching assistant, who contributes far too much of the intellectual component of the student's program, so the student
  • 26. Discovering Diverse Content Through Random Scribd Documents
  • 27. "You saved my life, youngster, and I won't forget it. Come aboard my ship before sailing and let me thank you, won't you? I'll be fit and hearty in a day or so." Dan liked the looks and manner of the big, brown-bearded Englishman and warmly replied: "Pulling you out of the wet was the least we could do. I hope your head will mend all right. Captain Wetherly will be glad to see you on board again, sir." Dan lent a hand as far as the hack and then sought Captain Wetherly's room. The light was burning and the deck-hand dared to enter on the chance of having a talk with "Uncle Jim," whom he found reading a novel in his bunk. The boy had many questions to ask, but he was not ready to go straight to the heart of the matter, and so began: "Jerry Pringle acted kind of ugly and uneasy, didn't you think? I suppose he was mad at getting spilled into the harbor. You and he never did seem to be very fond of each other." Captain Jim threw down his book and sat up in his bunk with a rather grim smile as he replied: "You're no fool, Dan, though you aren't more than half as old as me. And you have lived ten of your years in Key West. I know you think the world of young Barton Pringle. He is a fine, clean lad, the son of his mother through and through. But there's a different strain in that dad of his, and you know it. You want to find out what I think of to- night's business, don't you? Well, I think the big Englishman might have picked better company." "But he said some things about getting ten thousand dollars for losing his ship and so on, Uncle Jim, and I heard more than you did. He was worried to death for fear he had talked too much. The wrecking business in Key West is square and honest as far as I know, but ship captains have put their vessels on the Reef on
  • 28. purpose in the old days and the wreckers helped plan it beforehand. And I can't help wondering if Jerry Pringle came to Pensacola to fix up a deal with this captain of the Kenilworth to lose his ship on the next voyage out from London to Vera Cruz. There would be rich salvage and loot in a general cargo, wouldn't there? She's a mighty big steamer." Captain Jim stroked his chin and was so long silent that Dan began to fidget. Then, as if rousing himself from some very interesting reflections, the elder man drawled in a tone of mild reproof: "There isn't a bit of evidence that would hold water, Dan. I may have my suspicions, but perhaps they are all wrong, and if we said a word it might ruin a good ship-master with his owners. Jerry Pringle and he must have been up to their ears in conversation when they let us run 'em under, and I wish the big Englishman could prove an alibi for the time we had him, aboard. Better forget it." Dan bit his lip and appeared so gloomy and forlorn that his uncle was moved to ask what troubled him. "It's Bart Pringle," said Dan, and his voice was not quite steady. "When I meet him in Key West I'll have a secret to hold back from him, and it's about his own father. Oh, I can't believe there's anything to it. And there's Bart's mother! Well, I think I'll turn in, Uncle Jim. Good-night." Late in the next afternoon the Resolute cast off from the coal wharf and swiftly picked up headway as her powerful engines began to urge her, with tireless, throbbing cadence, toward her distant home port of Key West. Presently she surged past a long, deep-laden cargo steamer from whose stern rippled the flaming British ensign. It was the Kenilworth, and Captain Jim and Dan Frazier stared at her with curious interest. A tall, broad-shouldered, brown-bearded figure was leaning against the railing of her bridge. A strip of bandage gleamed white beneath
  • 29. the visor of his cap. He flourished an arm in farewell to the Resolute whose deep-toned whistle returned a salute of three blasts. Dan passed by the wheel-house door on an errand for the mate and could not help saying aloud to himself: "It must have been a nightmare. That Captain Bruce looks like too fine a man to think of such a dreadful thing!" Captain Jim Wetherly overheard the comment and seemed to echo this verdict as he remarked in a reverent and sympathetic tone: "Lead Captain Malcolm Bruce not into temptation, for Jerry Pringle is a hard customer to have any dealings with, on or off the Reef."
  • 30. CHAPTER II THE "RESOLUTE" FATHOMS THE PLOT As the Resolute steamed into Key West harbor, Dan Frazier was on the lookout for his friend Barton Pringle who almost always ran down to the wharf when the whistle of Captain Wetherly's tug bellowed the tidings of her return from sea. This time, however, Dan felt that a shadow had fallen over their close comradeship which had been wholly frank and confiding through all their years together. Dan could not forget the events of the night in which Barton's father had behaved like a man caught in the act of planning something dark and evil. But the sight of Barton Pringle waiting on the end of the wharf to catch the Resolute's heaving lines and welcome him home, made Dan wonder afresh if he had not been too hasty and suspicious. Barton's honest, beaming face was in itself a voucher for his bringing up amid sweet and wholesome influences. Nor was Dan ready to believe that a bad father could have such a straight and manly son. Before the boys were within shouting range of each other, Captain Wetherly sent for Dan and told him: "You can stay home until you get further orders. I don't expect to leave port again for several days. Tell your mother that I will run in for a little while after supper to-night." Dan thanked him with a grin of delight and ran below to yell to Barton Pringle on the wharf: "Hello, Bart. Come aboard and help me scrub decks and get things ship-shape and I'll be ready to jump ashore just so much sooner." Barton made a flying leap aboard as soon as the lines were made fast, and asked as he picked up a pail and broom:
  • 31. "What kind of a voyage did you have, Dan? Anything exciting happen?" "Nothing to speak of," replied Dan, and he felt his face redden with a guilty sense of secrecy. He was about to say that he had met Barton's father in Pensacola, without mentioning how or where, when the other lad spoke up: "I tried to get away for a little trip myself. Father went up the Gulf on the mail steamer and I begged him to take me along. But he was going only to Tampa to see about buying a couple of sponging schooners, and he said he was in too much of a hurry to bother with me." "Going only to Tampa," echoed Dan with a foolish smile. "Oh, yes, only as far as Tampa. Sorry you had to miss it, Bart. How's everything with you? Have you bent the new main-sail on the Sombrero?" Barton plunged into an excited discussion about the fast little sloop which the boys owned in partnership, while Dan tried to keep his wits about him, for he was thrown into fresh doubt and uneasiness by the news that Jeremiah Pringle had said he was going to Tampa instead of Pensacola. Usually the two boys had so many important matters to talk about that one could find a chance to break in only when the other paused for lack of breath, but now Dan found it hard to avoid awkward silences on his part. He was glad when old Bill McKnight, the chief engineer of the Resolute, waddled up to them and announced with a sweeping gesture toward the city streets: "Back again to the palm trees and the brave Cubanos and the excitements of a metropolis smeared over a chunk of coral reef so blamed small that I'm scared to be out after dark without a lantern for fear I'll walk overboard. I'm due to start a revolution in Honduras, and to-day I enlist a few hundred brave and desperate Key West cigar-makers, Dan. I'm perishin' for a little war and tumult. Look out for my signal rockets."
  • 32. With that Mr. McKnight jauntily twirled his grizzled moustache and ambled up the wharf. He had been engineer of the Resolute when she was running the Spanish blockade of Cuba, as a filibuster to carry arms and ammunitions to the revolutionists, and his cool- headed courage had fetched the tug out of some perilous places. The ponderous, good-natured engineer was very fond of Dan and every little while invited him, with all seriousness, to join some new and absurd scheme for touching off a Spanish-American revolution, with dazzling promises of loot and glory. The boys laughed as they gazed after him, and Barton said: "Filibustering must keep your hair standing on end, eh, Dan? I reckon it beats wrecking, though you couldn't get an old Key Wester to admit it. There hasn't been a wreck on the Reef for goodness knows how long. Father promised to take me with him on the next wrecking job if it isn't blowing too hard when the schooners go out to the Reef." "Well, you can count on seeing Captain Jim Wetherly and the Resolute on the job no matter how hard she blows," smiled Dan with a spark of the rivalry which flamed high between the tow-boat and the schooner fleet. Willing hands made short work of Dan's tasks, and he hurried into his shore-going clothes while Barton swung his legs from the bunk and retailed the latest news about ships, and the sponge market, and the High School base-ball team which had won a match from the soldiers of the garrison. They parted a little later, Dan eager to run home and see his mother, and Barton anxious to make the Sombrero ready for a trial spin. As Dan sped toward the cottage on the other side of the narrow island, he said to himself with a puzzled frown: "Everything Bart talked about made me think of the other night in Pensacola: his father's going away, and the next wreck on the Reef, and all that. And he thinks his father is the strongest, bravest man
  • 33. that ever went to sea. Maybe he is, but I wish he wasn't related to Bart." A slender, sweet-faced woman in black was waiting in a dooryard shaded by tropical verdure as Dan rounded the corner. She had heard the far-echoing, resonant whistle of the Resolute, and knew that her boy was home again. Her husband, for many years employed in the Key West Custom House, had died only two years before, and the love and yearning in her eyes at sight of Dan would have told you that he was her only child and her all-in-all if you had never seen them together before. He was taller than she, and, as her sturdy son stooped to kiss her with his arms about her neck, she said: "I wanted to be at the wharf to meet you, Danny boy, but I couldn't leave home in time. Bart Pringle's mother ran in to talk to me about sending him away to school. I told her I wanted to do as much for you, but the way wasn't open yet. They can afford it, and Bart is too bright and ambitious to settle down in a Key West rut." They walked to the wide veranda across which the cool trade-wind swept, and Mrs. Frazier ordered Dan to take the biggest, easiest wicker chair, after which she vanished indoors and almost instantly reappeared with a plate laden with pie and doughnuts. "You had breakfast in that stuffy little galley, I suppose," laughed she, "but I know you are always hungry. You can stow these trifles away as a deck-load, can't you?" Dan confessed that he could carry any amount of cargo of this kind and then, between bites of a home-made doughnut, spoke very earnestly: "Bart ought to go North to school, mother, and I will tell him so and back you up for all I'm worth. It will do him good to break away from home. And Uncle Jim Wetherly will put up the same line of argument to Mrs. Pringle whenever you say the word."
  • 34. "Jim is my dearest brother, but I can't picture him as showing very much excitement about Bart's education," she responded. "He thinks there's no finer thing in the world than to be master and owner of a sea-going tow-boat. Why do you think he will be interested, Dan?" Her son took her hand in his hard, sun-burned paw and with a stammering effort began his confession of all that he had heard and seen after Jerry Pringle and the English ship-master had been run down in their small boat. The mother listened with wide-eyed astonishment, and then with something like indignation she cried: "Why, Dan, you ought to be writing novels for a living! That poor Captain Bruce of the Kenilworth was out of his head, and you know that Jerry Pringle has a sour, gruff way with him even when he's on dry land. I can't believe it of Mary Pringle's husband. It is a dreadful thing to suspect him of, plotting to wreck a fine, big steamer." "That's just like a woman," declared Dan with a very grown-up air of wisdom. "Mrs. Pringle hasn't anything to do with it. And you are like Uncle Jim, always refusing to think other folks are a bit less square and decent than you are. Ask him to-night what he thinks about it, but don't breathe a word to anybody else, will you?" "I shall scold him for putting such silly ideas in your head," firmly announced Mrs. Frazier. "You couldn't have pieced this plot together all by yourself, even if you are as big and strong as a young tow- boat." "All right," said Dan good-humoredly. "Only I hope Barton will go away to school before the explosion happens. For if I'm right, Jerry Pringle may be in disgrace before he's a year older. Captain Jim will never let up on him if the Kenilworth does happen to be stranded on the Reef." When Captain Wetherly strolled in after supper, his sister began at once to cross-question him. He evaded her as far as possible and finally declared:
  • 35. "I knew that Dan would tell you. I don't want him to keep anything from his mother. But it must go no farther than this. I will say this much, that when the Kenilworth is due in the Florida Straits on her next voyage outward bound, the Resolute will be a good deal less than a thousand miles away. And just for curiosity I have cabled to London to find out if she is really chartered to Vera Cruz for her next voyage, and what kind of a reputation her owners bear. They may be interested in losing her, do you see? "Speaking of cables, Dan," he continued; "I got orders this afternoon to go to Charleston at once and tow that big suction dredge to Santiago. We shall be able to get away in a couple of days. You had better come aboard to-morrow night." "Why, you'll be gone for weeks and weeks, Dan," sorrowfully cried his mother. "I won't waste any time, nor try to save coal on this voyage," said Captain Jim with a grim smile. "I want to be a good deal nearer the Reef than Santiago, about two months from now." "It's a long, long while to have my boy away from me," Mrs. Frazier murmured with a sigh. "But this tremendous conspiracy will be all blown out of your heads before you come home again." After a luxurious night's slumber in a real bed, Dan felt as if the cobwebs had been brushed from his busy brain and that the bright world held better employment than brooding over what might happen to somebody else. He set forth to find Barton and arrange a match race between the Sombrero and a rival craft, to be sailed before Dan had to go to sea. The challenge being accepted on the spot, there was much to be done in a very few hours, and Dan heartily agreed with Barton's opinion delivered from the cockpit of their rakish craft: "It is a pity we have anything to do but sail boats for the fun of it. What a bully sou'west breeze we're going to have this afternoon, Dan! Can you coax old Bill McKnight to come along for ballast?"
  • 36. "Yes, if we promise him to smuggle some rifles and dynamite in the hold," laughed the other. After dinner, Dan sauntered along the water front in the hope of finding the mighty bulk of the chief engineer to serve as two hundred and seventy pounds of desirable live ballast. The south- bound mail steamer, from Tampa for Havana, had just landed her passengers, and foremost among them loomed the tail and lanky figure of Jeremiah Pringle. The wrecking master spied Dan and hurried to meet him in the narrow street. His manner was no longer hostile and sullen, and Dan was amazed to have a greeting hand stretched toward him and to hear a cordial voice: "How's the boy? You and Bart as busy as ever? I went up the Gulf to buy a schooner or two, and I found a beauty. I need a mate for her, Dan. You are young, but you know more about salt water than most men. It means double the wages of a deck-hand on that sooty old tow-boat. I want you to go to Tampa and help fetch her down right away, which is why I spring the proposition on you kind of off-hand and sudden." It was a chance at which Dan would have jumped a week before. Something held him back, however, and, although he did not take time to reason it out, he vaguely felt that Jeremiah Pringle was trying to bribe him to keep his mouth shut. But he had a natural fear of making an enemy of such a man as this, and he swiftly decided to make no mention of the night in Pensacola. That was a matter for Captain Jim Wetherly to handle. Dan was ready to stand by his guns, however, so far as his own honesty was concerned, and he stoutly replied: "That is a big thing to have come my way, Captain Pringle, and I ought to thank you. But I don't care to take it. My mother wants me to stick by Captain Jim Wetherly if I'm going to stay afloat, and she knows best." Jerry Pringle looked black, but forced a smile as he growled:
  • 37. "One thing you've got from your Uncle Jim is a swelled head. Well, we'll say no more about it; nothing at all about it, understand?" The last words were spoken with a threatening earnestness, and Dan understood what was meant. He nodded and went on his way, for once anxious to get to sea, away from a situation in which he seemed to become more and more befogged. He found Bart dancing jig-steps with impatience, and trying to listen to a long-winded yarn delivered by Mr. Bill McKnight who had been already kidnapped for the afternoon. The Sombrero sailed like a witch in the race, the live ballast shifted himself with more agility than the boys had dreamed he could display, and the match was won with the lee-rail under and the cockpit awash. Mrs. Frazier watched the finish from a wharf and invited Bart and the engineer to come home with Dan for a festive supper party in celebration. There could be no long faces or heavy thoughts at such a time, and Dan forgot the shadow and laughed himself into a state of collapse along with his mother and Bart when Mr. McKnight, with a wreath of scarlet ponciana blossoms on his bald head, danced Spanish fandangos until the cottage shook from floor to rafters.
  • 38. The Sombrero sailed like a witch in the race They all escorted Dan down to the Resolute in the starlit evening and sat on the guard-rail while the chief engineer fished a guitar from under his bunk and sang Cuban serenades, leading off with "La Paloma." It was as merry as such a parting hour could be, but there
  • 39. were tears in the mother's eyes when she kissed Dan good-night, and her voice was not steady when she whispered, "God bless and keep you, my precious boy." When it came to saying good-by to Bart, Dan was more serious than usual and, he held fast to his comrade's hand for a moment while he looked him in the eyes and said: "Blow high, blow low, you will find me standing by, Bart. Good luck and lots of it." Shortly after daylight next morning the Resolute churned her way out of the placid harbor and laid her coastwise course for Charleston. It proved to be an uneventful run with pleasant weather and a favoring sea. Captain Wetherly had nothing to say about the steamer Kenilworth until they reached Charleston where he found a cablegram from London waiting for him. He read it aloud to Dan as soon as they happened to be alone. "Unable to send required information until later. Will communicate your next port." "It might have cleared up this Kenilworth business," said Captain Jim. "However, we may get a message at Santiago." But the Resolute was not to see Santiago as soon as her master expected. There was a week's delay in getting the great suction dredge ready to begin the voyage. Then, when the Resolute had taken hold of the clumsy monster, for all the world like a bull-dog trying to drag a dry-goods box, the captain of the dredge was hurt by a falling bolt and there was more delay at anchor while a new skipper could be sent for. When, at last, the unwieldy tow was got to sea, strong head-winds buffeted her day after day and urged the panting, sea-swept Resolute to her best efforts to keep up steerage way. She crept southward like a snail, eating up coal at a rate which compelled
  • 40. Captain Wetherly to put into Nassau, and again into the harbor of Mole St. Nicolas at the western end of Hayti. Twice the dredge snapped her hawsers and broke clean adrift. When the weary tug and her tow crept in sight of the Morro Castle at the mouth of Santiago harbor, Bill McKnight almost wept as he surveyed his engines and boilers. Sorely racked and strained they were, and Captain Jim tried to comfort him by declaring that no other fat engineer could have patched and held them together to the end of the voyage. Making temporary repairs was a costly and tedious undertaking, and the crew of the Resolute tired of the charms of Santiago and grew restless and homesick for Key West. While Dan, the captain, and McKnight were eating lunch ashore one day, a swarthy, dapper clerk from the cable office sought the Venus Café with a message which he had tried to deliver on board the tug. It was for Captain Wetherly who read it with an air of mingled surprise and chagrin. With a glance at the engineer who was blissfully absorbed over his third plate of alligator pear salad, Captain Jim remarked as he handed the sheet to Dan: "It is from London. Well, the cat is out of the bag, and we might as well let McKnight in. We are going to need him before we get through with this job, and need him bad. I suppose I ought to have been more suspicious, but it sounded too rotten to be true. Bill, you must have that engine room in shape this week if it breaks your back. We are going to make a record run home to Key West." Dan read in silence before handing the cablegram to Captain Wetherly. "Kenilworth cleared for Vera Cruz. Heavily insured. General cargo. Owners hard hit by recent losses. Will bear watching." Captain Jim hammered the table with his fist and tried to speak in an undertone as he hotly exclaimed:
  • 41. "This confidential report makes my suspicions fit together like the pieces of a puzzle. I couldn't for the life of me understand how the master of a big steamer could afford to ram her ashore and lose her, and his berth and his reputation with it, for ten thousand dollars. But if he knew that his owners would shield him and stand in with him, why, of course, he might be tempted to clean up ten thousand dollars for himself when a man like Jerry Pringle crossed his bows and passed him a few hints. A lot of good it would have done for me to cable Captain Bruce's owners and give them warning of what we heard that night in Pensacola harbor. They would have laughed at me as a meddlesome idiot. Cleared for Vera Cruz, has she? She does her ten knots right along, I picked up that bit of information at Pensacola. Allow her twenty days to the Reef." Bill McKnight had dropped his fork and was purple with suppressed excitement. When the captain fetched up for lack of breath, he blurted in a hoarse whisper: "It doesn't take a axe to drive an idea into my noddle. As near as I can make out, though your bearings are considerably overheated, Captain, there is scheduled to be a large and expensive wreck on the Reef, assisted by her skipper and one Jeremiah Pringle. It sounds like the good old times before the light-houses crippled the wrecking industry. And we Resolutes propose to be first on hand to pull her off and disappoint certain enterprising persons?" "Disappoint 'em!" fairly shouted Captain Jim. "If the Kenilworth does go ashore, I'll fetch that vessel off the Reef if it tears the Resolute to kindling wood. I'll break their rotten hearts and show them what honest wrecking is." "I didn't throw away that clamp I made to hold the safety-valve down, Captain," chuckled Bill McKnight. "And I ain't afraid to use it again, either."
  • 42. CHAPTER III THE RACE FOR THE "KENILWORTH" Chief Engineer Bill McKnight hoisted himself up the iron ladder that led from the fire-room of the Resolute and tottered on deck gasping for breath. He was begrimed from head to foot, the sweat had furrowed little streaks in the mask of soot and grease which covered his ample countenance, and his eyes were red with weariness and want of sleep. He had shoved the tug back to Key West at her top speed, and now he was toiling night and day to make her ready for whatever summons might come for a tussle on the Reef. Captain Wetherly found him slumped against the deck-house with his head in his hands and exhorted him cheerily: "Don't give up the ship, Bill. It is a great repair job that you've done, and the worst is over. The new tubes are most all in, aren't they?" "The boilers will be as good as new," grunted McKnight, "but how about my bronchial tubes, Captain? I can't plug them up and make steam same as I plugged the boilers and fetched you back from Santiago. I'm so full of cinders inside that I rattle when I walk. But give me another week and the boat will be fit to hitch a hawser to this benighted island of Key West and tow it out to sea. Anything new ashore?" Captain Jim sat down beside the engineer and made sure that they could not be overheard as he began: "Dan has been watching Jerry Pringle's fleet of wrecking vessels for me. Those two schooners he bought in the Gulf have come into port, and it is mighty little sponging he intends to do with them at present, Bill. They look fast and they can stow lots of cargo. And Pringle has been overhauling his other schooners and has chartered
  • 43. three more in Key West. He says he intends to send them out to join the mackerel fleet." "Anything doing in the tow-boat line?" asked McKnight with a new gleam of interest in his damaged eyes. "If Pringle aims to tackle a certain job that may be reported from the Reef pretty soon, he will have to make a bluff at pulling the steamer off, won't he? There might be a small fortune in salvage, besides looting the cargo out of her." "He is dickering for some kind of a time charter on the Henry Foster," snapped Captain Jim. "She couldn't pull a feather-bed off the Reef without breaking down. And I understand he has been cabling up the Gulf about another tug or two." "Well, we can get all the tow-boats we need and good ones, can't we?" beamed McKnight. "Maybe we can't handle most any kind of a wrecking job ourselves! And there won't be any bluffs about it when we take hold." "I'm certainly sorry for Dan, poor boy," said Captain Jim with a sigh. "He feels as if he were spying on Bart's father. And to make it worse, Bart is going to sail with the old man for a while and the lad will be mixed up in this nasty mess as sure as fate, and he will be on the wrong side of it. Here comes our Dan now. Drop the subject, Bill. It only makes the youngster more unhappy." Dan Frazier had passed some restless nights since his return to Key West, but his mind was too sunny and youthful to believe that things were ever as bad as they might be. He found comfort in the hope that Captain Wetherly would spoil the plot to lose the Kenilworth. He had implicit confidence in his uncle's ability to win against any odds with the stanch Resolute, and now that a fair and open battle against Jerry Pringle was assured, Dan found himself eager for the fray. Barton had told him that morning: "Father and mother are talking of sending me North to school, but I'm going to rough it at sea with father for a month or so. He said he
  • 44. tried to get you to work for him. I knew you wouldn't leave Captain Jim, but maybe we might have been lucky enough to work on a wreck together." "You can't tell, Bart. Perhaps we shall, but we may be working against each other. I'll back Captain Jim Wetherly to be first man aboard the next vessel that goes on the Reef." "Captain Jim is a good man," declared Bart, "but it will be a cold day when he lays alongside a wreck ahead of that daddy of mine." The boys were busy with their unbeaten sloop Sombrero, and one day slid into another while Dan employed much of his spare time in helping his mother about the house and in painting the chicken- house, the fences, and porch with great pride in the spick-and-span results. Mrs. Frazier still professed to take no stock in the plot hatched by "Barton's father and Mary Pringle's husband," but she was nervous and absent-minded at times, and there was even more affection than usual in her manner toward Bart. Dan tacked a calendar at the head of his bed and crossed off the days one by one, saying to himself when he awoke and looked at it: "Twenty days out from London, as Uncle Jim figured it, and the Kenilworth is one day nearer the Reef." Twenty-two days had been counted when Captain Jim called at the cottage and told Dan to go aboard the Resolute and stay there until further orders. When the deck-hand reported for duty, he found all hands of the crew either at work on board or within call on the wharf. Bill McKnight had steam in his boilers and, although the fires were banked, he had just finished stowing below a generous supply of resinous pine wood, oil-soaked cotton waste, and a barrel of turpentine for use as emergency fuel. "I lost thirty-five pounds of weight in three weeks," snorted the engineer, "but I mended the old hooker to stay mended. Ho, ho, there goes the Henry Foster to sea, Captain. Wonder if there's
  • 45. anything doing so soon? Her engines sound like a mowing-machine trying to cut a path through a brick-yard." "Don't worry about her," muttered Captain Jim. "Pringle isn't aboard her. We won't leave here until he gets uneasy. He is a good deal better posted than I am about his infernal program and we——" Captain Jim stopped short, for Barton Pringle unexpectedly appeared on deck and announced to Dan: "I'm going up the Hawk Channel with father at daylight to look for one of our sponging vessels that's reported ashore near Bahia Honda Key. Thought I'd say good-by." Dan could not help glancing at Captain Jim as he replied with a quiver of excitement in his voice: "We may be running up the outside channel before you get back, Bart. Perhaps we shall sight you. Hope you have a good trip." Barton was in a hurry and jumped ashore with a wave of his hand to the chief engineer. When he was out of ear-shot Dan observed with a long face: "I would give six months' wages if I could make Bart stay home. Do you suppose his father is really going to sea at daylight, or is he just using Bart to fool us?" "I haven't been walking in my sleep," dryly responded Captain Jim. "There's a hundred and fifty miles of the Reef between here and Miami and I don't intend to follow any decoy ducks and fetch up at the wrong end of it. I figure on getting a report of any disaster as soon as the next man." The next day passed without tidings. Jeremiah Pringle had vanished from his haunts in Key West, and four of his schooners were not to be found at their moorings. Another day dragged by, Bill McKnight was stewing with impatience and Dan Frazier was losing his appetite while Captain Jim Wetherly remained cheerful and unruffled.
  • 46. He was like another man, however, when a message came to him at noon on the fourth day of waiting. It was from the cable office and he had no more than glanced at it before he darted on deck, ordered the mate to get the crew aboard, shouted down a speaking- tube to Bill McKnight, and took his station at the wheel. His keen- witted, masterful energy seemed to thrill the Resolute with life and action. Black smoke gushed from her funnel as her stokers toiled in front of the furnace doors. The engines were turning over when the last deck-hand leaped aboard, and as the dripping hawsers were hauled in, the tug was moving out into the stream. Key West island was over her stern before Dan found time to run up to the wheel-house. Captain Jim slipped a crumpled bit of paper into his fist and motioned for him to keep it to himself. It was from the marine observer at Jupiter Inlet, a hundred miles to the northward of the Florida Reef: "Steamer Kenilworth southbound passed seven this morning. Signalled steering gear disabled by heavy weather but able to proceed." Dan's faith in human nature, as it had to do with the master of the Kenilworth, had been so severely shocked that he wondered whether the report of her mishap could be true. He was not shrewd enough to perceive, however, what Captain Jim whispered as he went below to see how things were moving in the engine-room. "Crippled steering gear, bosh. Her skipper has to fake up some excuse for striking the Reef." Dan could scarcely believe that the curtain had really risen on this seafaring melodrama in which he was to be an actor. A stately ship was moving blindly toward an ambush which might be the death of her. And racing to find and befriend her was this lone tug whose throbbing heart of steel shook her stout hull from bow to stern as she tore through the long head-seas on the edge of the Gulf Stream. The afternoon was already waning and night would overtake the
  • 47. Resolute before she could reach the upper stretches of the Reef. Captain Wetherly felt certain that the Kenilworth would not be rammed on the coral ledges in broad daylight, and he foresaw a desperate game of hide-and-seek between darkness and dawn. But he held to the doctrine that with anything like even chances an honest man will win against a rascal in the game of life, afloat or ashore. The north-east wind was steadily freshening and the sky had become gray with drifting clouds. As dusk crept over the uneasy sea a mist-like rain began to drizzle. The master of the Kenilworth might reasonably lose his bearings if the night grew much thicker. Bill McKnight emerged from his sultry cavern long enough to grumble to Dan: "What's to hinder our running past that steamer before morning, I want to know, hey, boy?" "You wouldn't worry if you could watch Captain Jim hug the Reef," assured Dan. "It's like walking a tight-rope. I thought we were going to climb right up into the American Shoal light-house." "Well, this old tug is doing her fifteen knots, Dan, which is faster than she ever flew before," chuckled the chief engineer, "and if we touch bottom, you'll know it all right. Look up yonder at my fireworks." Dan stared at a banner of solid flame that streamed from the funnel which glowed red hot for a dozen feet above the deck. With a cry of alarm he ran to the upper deck-houses which were built just fore and aft of the funnel and found the wood-work charred and smoking. He shouted down to McKnight who replied with a laugh: "It isn't my affair if your superstructure burns up. My orders are to make steam. Better mention it to the skipper." Dan rushed to the wheel-house but Captain Jim received the news as if it were the merest trifle. He was sweeping the sea with his
  • 48. night-glasses and exhorting the mate at the wheel to "hold her as she is and keep your nerve." To Dan he replied airily: "Caught afire, has she? Good for Bill McKnight. He's delivering the goods. Get some men with buckets and put the fire out. I've no steam to waste in starting the pumps and putting the hose on it." The deck force was taking turns at shovelling coal to reinforce the stifled stokers, and those off watch followed Dan with cheers. They knew that a race was on, and it lightened their toil to know that the Resolute was pounding toward her goal, wherever it was, with every ounce of power in her. Captain Jim joined the fire-fighters long enough to yell to them: "Look out for rockets ahead. The first man to sight distress signals from the Reef gets ten dollars and a new hat." A brawny negro stoker wiped the sweat from his eyes as he bobbed on deck and panted: "When Cap'n Jim smell a wreck she's sure gwine be where he say. If he wants to find 'stress signals he better look amongst us poor niggers in the fire-room." Midnight came and no one thought of sleep. The excitement had spread even to the cook and the galley boy who thought they saw rockets every time a match was lit up in the bows. Dan gazed out into the starless night and listened to the clamor of the parting seas alongside with frequent thoughts of Barton Pringle who was somewhere out here, proud of his father's seamanship and daring, loyal to his interests, trusting him as Dan trusted his Uncle Jim. Now like pawns on a chess board, the two boys were to play their parts on the opposing sides of a conflict which would be fought to the bitter end. Dan was aroused by a hoarse shout from the bridge of the Resolute: "Red rocket two points off the port bow."
  • 49. Dan wheeled and looked forward while his breath seemed to choke him. A second rocket soared skyward, like a crimson thread hung against the curtain of night. "Hold her steady as she is," shouted Captain Jim from his post on the bridge. "The weather has cleared a bit and that signal was a long way off." There was an exultant ring to his strong voice as if he were glad to have the climax in sight. He sent for Dan and told him to stay on the bridge and look for answering signals. "It's the Kenilworth, a thousand to one," said the captain of the Resolute. "And if Jerry Pringle's schemes haven't missed fire, his tug or one of his schooners will just happen to be within signalling distance. Ah, by Judas, there goes his answer, a rocket way out to seaward. Pringle was afraid to hug the Reef on a thick night. He missed the Kenilworth when she passed inside of him. It may possibly be a merchantman that has seen the Kenilworth's signals, but we take no chances." Captain Wetherly shouted the tidings down the tube to the engine- room force, and the hard-driven tug tore her way through the heavy seas in the last gallant burst of the home-stretch. Back through the speaking-tube bellowed the voice of the chief engineer: "I've just put the clamp on the safety-valve, Captain. She's carrying thirty pounds more steam than the law allows, and if she cracks she'll crack wide open. Hooray! Give it to her!" As if the captain of the stranded steamer were content to know that his message had been seen and answered, he sent up no more rockets, nor did any more answering signals gleam out to seaward. It was a race in the dark. The Resolute and her rival, if such it was, must run down two sides of a triangle whose apex was the unseen vessel on the Reef. Captain Jim had taken the compass bearings of the Kenilworth's rockets and, regardless of the risk he ran in driving his steamer along the very fangs of the Reef, he held her in a
  • 50. 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! ebookfinal.com