The Hidden Language of Computer Hardware and Software
Second Edition
Charles Petzold
Code: The Hidden Language of Computer Hardware and Software: Second Edition
Published with the authorization of Microsoft Corporation by: Pearson Education, Inc.
Copyright 2023 by Charles Petzold.
All rights reserved. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, request forms, and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please visit www.pearson.com/permissions.
No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein.
ISBN-13: 978-0-13-790910-0
ISBN-10: 0-13-790910-1
Library of Congress Control Number: 2022939292
ScoutAutomatedPrintCode
Trademarks
Microsoft and the trademarks listed at http://www.microsoft.com on the Trademarks webpage are trademarks of the Microsoft group of companies. All other marks are property of their respective owners.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an as is basis. The author, the publisher, and Microsoft Corporation shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book or from the use of the programs accompanying it.
Special Sales
For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at or (800) 382-3419.
For government sales inquiries, please contact .
For questions about sales outside the U.S., please contact .
About the Author
Charles Petzold is also the author of The Annotated Turing: A Guided Tour through Alan Turings Historic Paper on Computability and the Turing Machine (Wiley, 2008). He wrote a bunch of other books too, but theyre mostly about programming applications for Microsoft Windows, and theyre all obsolete now. He lives in New York City with his wife, historian and novelist Deirdre Sinnott, and two cats named Honey and Heidi. His website is www.charlespetzold.com.
Preface to the Second Edition
The first edition of this book was published in September 1999. With much delight I realized that I had finally written a book that would never need revising! This was in stark contrast to my first book, which was about programming applications for Microsoft Windows. That one had already gone through five editions in just ten years. My second book on the OS/2 Presentation Manager (the what?) became obsolete much more quickly. But Code, I was certain, would last forever.
My original idea with Code was to start with very simple concepts but slowly build to a very deep understanding of the workings of digital computers. Through this steady progression up the hill of knowledge, I would employ a minimum of metaphors, analogies, and silly illustrations, and instead use the language and symbols of the actual engineers who design and build computers. I also had a very clever trick up my sleeve: I would use ancient technologies to demonstrate universal principles under the assumption that these ancient technologies were already quite old and would never get older. It was as if I were writing a book about the internal combustion engine but based on the Ford Model T.
I still think that my approach was sound, but I was wrong in some of the details. As the years went by, the book started to show its age. Some of the cultural references became stale. Phones and fingers supplemented keyboards and mice. The internet certainly existed in 1999, but it was nothing like what it eventually became. Unicodethe text encoding that allows a uniform representation of all the worlds languages as well as emojisgot less than a page in the first edition. And JavaScript, the programming language that has become pervasive on the web, wasnt mentioned at all.
Those problems would probably have been easy to fix, but there existed another aspect of the first edition that continued to bother me. I wanted to show the workings of an actual CPUthe central processing unit that forms the brain, heart, and soul of a computerbut the first edition didnt quite make it. I felt that I had gotten close to this crucial breakthrough but then I had given up. Readers didnt seem to complain, but to me it was a glaring flaw.
That deficiency has been corrected in this second edition. Thats why its some 70 pages longer. Yes, its a longer journey, but if you come along with me through the pages of this second edition, we shall dive much deeper into the internals of the CPU. Whether this will be a more pleasurable experience for you or not, I do not know. If you feel like youre going to drown, please come up for air. But if you make it through , you should feel quite proud, and youll be pleased to know that the remainder of the book is a breeze.
The Companion Website
The first edition of Code used the color red in circuit diagrams to indicate the flow of electricity. The second edition does that as well, but the workings of these circuits are now also illustrated in a more graphically interactive way on a new website called CodeHiddenLanguage.com.
Youll be reminded of this website occasionally throughout the pages of this book, but were also using a special icon, which youll see in the margin of this paragraph. Hereafter, whenever you see that iconusually accompanying a circuit diagramyou can explore the workings of the circuit on the website. (For those who crave the technical background, I programmed these web graphics in JavaScript using the HTML5 canvas
element.)
The CodeHiddenLanguage.com website is entirely free to use. There is no paywall, and the only advertisement youll see is for the book itself. In a few of the examples, the website uses cookies, but only to allow you to store some information on your computer. The website doesnt track you or do anything evil.
I will also be using the website for clarifications or corrections of material in the book.
The People Responsible
The name of one of the people responsible for this book is on the cover; some others are no less indispensable but appear inside on the copyright and colophon pages.