Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Randall Hyde

Rating No ratings yet

Understanding the Machine, the first volume in the landmark Write Great Code series by Randall Hyde, explains the underlying mechanics of how a computer works. This, the first volume in Randall Hyde's Write Great Code series, dives into machine organization without the extra overhead of learning assembly language programming. Written for high-level language programmers, Understanding the Machine fills in the low-level details of machine organization that are often left out of computer science and engineering courses. Learn: • How the machine represents numbers, strings, and high-level data structures, so you'll know the inherent cost of using them. • How to organize your data, so the machine can access it efficiently. • How the CPU operates, so you can write code that works the way the machine does. • How I/O devices operate, so you can maximize your application's performance when accessing those devices. • How to best use the memory hierarchy to produce the fastest possible programs. NEW IN THIS EDITION, COVERAGE OF: • Programming languages like Swift and Java • Code generation on modern 64-bit CPUs • ARM processors on mobile phones and tablets • Newer peripheral devices • Larger memory systems and large-scale SSDs Great code is efficient code. But before you can write truly efficient code, you must understand how computer systems execute programs and how abstractions in programming languages map to the machine's low-level hardware. After all, compilers don't write the best machine code; programmers do. This book gives you the foundation upon which all great software is built.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Write Great Code - Volume 1: Understanding the Machine (2nd Edition) — Reading Guide ## 【One-Line Pitch】 A practical, language-agnostic tour of computer hardware that shows high-level programmers exactly how their code translates into machine operations — essential reading for any developer who wants to write faster, more efficient software by understanding what happens beneath the abstraction layer. ## 【Book Arc】 - **Opening (~0%–9%)**: Establishes the book's mission — teaching machine organization to high-level language programmers without requiring assembly expertise — and outlines the full scope from numeric representation through I/O devices, with the table of contents revealing coverage of storage, filesystems, and miscellaneous peripherals. - **Early (~9%–19%)**: Defines what "great code" means (efficient CPU/memory use, readability, maintainability, robustness) and introduces the foundational concept that understanding binary, octal, and hexadecimal numbering systems is prerequisite knowledge for writing software that performs well on real hardware. - **Early (~19%–28%)**: Dives into numeric representation fundamentals — bit numbering in bytes, words, and double words — and explains practical conversion techniques like saturation arithmetic for clipping values when narrowing data types, plus binary-coded decimal (BCD) for business/database applications. - **Early (~28%–38%)**: Covers binary arithmetic and bit operations, showing how bitwise AND/OR can test bit patterns efficiently, and demonstrates real-world applications like packed date formats that treat multiple fields as a single machine word for faster comparisons and operations. - **Middle (~38%–47%)**: Explores floating-point representation in depth — why integers and fixed-point formats fail for certain calculations, how the IEEE 754 format works with sign, exponent, and mantissa fields, and the trade-offs between single, double, extended, and quad-precision formats, including normalization and denormalized values. ## 【Key Takeaways】 - **Machine literacy is the foundation of great code** (Early): Understanding how CPUs represent and manipulate data — binary, bit numbering, word sizes — directly impacts your ability to write efficient programs, regardless of your programming language. - **Saturation arithmetic is a practical fallback** (Early): When narrowing values (e.g., 32-bit to 16-bit), clipping to the nearest representable value is often preferable to raising exceptions — especially for audio/video where degraded output beats crashing; many CPUs support this via MMX/SSE/AVX instructions. - **BCD matters for business software** (Early): If you interface with databases or COBOL systems, understanding binary-coded decimal — where each nibble represents a decimal digit 0–9 — is essential, even though general-purpose languages rarely support it natively. - **Bitwise operations are your efficiency toolkit** (Early): Using AND to test bit patterns (like checking divisibility by 16 via the low 4 bits) can replace slower arithmetic operations, and packing multiple fields into a single word enables one-instruction comparisons. - **Packed data structures enable atomic operations** (Middle): By encapsulating related fields (like year/month/day) into a single double-word with careful field ordering, you can compare entire dates with a single unsigned integer comparison — a classic performance optimization. - **Floating-point is about dynamic range** (Middle): Fixed-point formats trade integer range for fractional precision; IEEE 754 solves this with a sign/exponent/mantissa design that lets you represent vastly different magnitudes, but normalization is critical for maintaining precision. - **Precision formats have real trade-offs** (Middle): From 32-bit to 128-bit quad-precision, each floating-point format balances precision, range, and hardware cost — the 80-bit extended format was a historical compromise that persists today. ## 【Reading Tips】 - **Skim the early chapters if you're comfortable with binary math** — the bit-numbering and base-conversion material (~19%–28%) is review for many programmers; focus instead on the practical applications like saturation and BCD. - **Deep-read the bit operations chapter (~28%–38%)** — the packed date format example is worth studying carefully because it demonstrates the mindset shift from "language-level thinking" to "machine-level thinking" that the whole book promotes. - **Pay attention to the multi-language examples** — the book deliberately rotates among C/C++, Pascal, Swift, Java, and assembly; if one language's syntax confuses you, skip to the accompanying explanation or another language's version of the same concept. - **Don't skip the floating-point chapter (~38%–47%)** — even if you rarely touch low-level math, understanding normalization and precision loss explains many "weird" bugs you'll encounter in real-world numerical code. - **Use the "For More Information" sections** — each chapter ends with pointers for deeper dives; these are valuable if you want to explore specific topics like USB design or RAID systems further. ## 【Coverage Limits】 This guide covers the book's opening through the floating-point chapters (~47% of the book). The later sections on CPU architecture, memory organization, and I/O devices (including the detailed USB, storage, and audio coverage visible in the table of contents) are not synthesized here — excerpts do not cover the book's treatment of 64-bit CPUs, ARM processors, or the memory hierarchy in sufficient detail. ##
Page 9
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii Chapter 1: What You Need to Know to Write ...
View in text
Excerpt 2
f the lan- guage it uses. 1.4 Characteristics of Great Code Different programmers will have different definitions for great code, so it’s impossible to prov...
View in text
Excerpt 3
result in your source code. Although there are calculators that can compute such results, you should be able to perform simple arithme- tic operations on bi...
View in text
Excerpt 4
ng the exponent until a 1 appears in the mantissa’s HO bit.3 Remember, the exponent is a binary exponent. Each time you increment the exponent, you multipl...
View in text
Excerpt 5
dard defines code points in the range U+000000 to U+10FFFF. Note that 0x10ffff is 1,114,111, which is where most of the 1,112,064 characters in the Unicode...
View in text
Excerpt 6
t 64 address lines on the chip. This is because pins are a precious commodity on large CPUs, and it doesn’t make sense to bring out extra address pins that...
View in text
Excerpt 7
integer, such as character, enumerated, and Boolean types). In this chapter, we’ll assume that the integer indices of an array are numerically contiguous (...
View in text
Excerpt 8
T values, so this section is a good place to declare them. The VMT declarations in this example define two symbols you can access in the HLA program: stude...
View in text
Tags
AI categories
TechnologyProgramming LanguageOS
ISBN: 171850036X
Publisher: No Starch Press
Publish Year: 2020
Language: English
Pages: 472
File Format: PDF
File Size: 5.6 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…