Code The Hidden Language of Computer Hardware and Software, Second Edition (Charles Petzold) (Z-Library)

Author: Charles Petzold

商业

No Description

📄 File Format: PDF
💾 File Size: 34.5 MB
36
Views
0
Downloads
0.00
Total Donations

📄 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.

📄 Page 1
(This page has no text content)
📄 Page 2
(This page has no text content)
📄 Page 3
(This page has no text content)
📄 Page 4
The Hidden Language of Computer Hardware and Software Second Edition Charles Petzold
📄 Page 5
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
📄 Page 6
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 corpsales@pearsoned.com or (800) 382-3419. For government sales inquiries, please contact governmentsales@pearsoned.com. For questions about sales outside the U.S., please contact intlcs@pearson.com.
📄 Page 7
Contents About the Author Preface to the Second Edition Chapter One Best Friends Chapter Two Codes and Combinations Chapter Three Braille and Binary Codes Chapter Four Anatomy of a Flashlight Chapter Five Communicating Around Corners Chapter Six Logic with Switches Chapter Seven Telegraphs and Relays Chapter Eight Relays and Gates Chapter Nine Our Ten Digits Chapter Ten Alternative 10s Chapter Eleven Bit by Bit by Bit Chapter Twelve Bytes and Hexadecimal Chapter Thirteen From ASCII to Unicode Chapter Fourteen Adding with Logic Gates Chapter Fifteen Is This for Real?
📄 Page 8
Chapter Sixteen But What About Subtraction? Chapter Seventeen Feedback and Flip-Flops Chapter Eighteen Let’s Build a Clock! Chapter Nineteen An Assemblage of Memory Chapter Twenty Automating Arithmetic Chapter Twenty-One The Arithmetic Logic Unit Chapter Twenty-Two Registers and Busses Chapter Twenty-Three CPU Control Signals Chapter Twenty-Four Loops, Jumps, and Calls Chapter Twenty-Five Peripherals Chapter Twenty-Six The Operating System Chapter Twenty-Seven Coding Chapter Twenty-Eight The World Brain Index
📄 Page 9
About the Author Charles Petzold is also the author of The Annotated Turing: A Guided Tour through Alan Turing’s Historic Paper on Computability and the Turing Machine (Wiley, 2008). He wrote a bunch of other books too, but they’re mostly about programming applications for Microsoft Windows, and they’re 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.
📄 Page 10
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. Unicode—the text encoding that allows a uniform representation of all the world’s languages as well as emojis—got less than a page in the first edition. And JavaScript, the programming language that has become pervasive on the web, wasn’t 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
📄 Page 11
show the workings of an actual CPU—the central processing unit that forms the brain, heart, and soul of a computer—but the first edition didn’t quite make it. I felt that I had gotten close to this crucial breakthrough but then I had given up. Readers didn’t seem to complain, but to me it was a glaring flaw. That deficiency has been corrected in this second edition. That’s why it’s some 70 pages longer. Yes, it’s 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 you’re going to drown, please come up for air. But if you make it through Chapter 24, you should feel quite proud, and you’ll be pleased to know that the remainder of the book is a breeze. The Companion Website
📄 Page 12
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. You’ll be reminded of this website occasionally throughout the pages of this book, but we’re also using a special icon, which you’ll see in the margin of this paragraph. Hereafter, whenever you see that icon—usually accompanying a circuit diagram—you 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 you’ll 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 doesn’t 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. In particular, I want to call out Executive Editor Haze Humbert, who approached me about the possibility of a second edition uncannily at precisely the right moment that I was ready to do it. I commenced work in January 2021, and she skillfully guided us through the ordeal, even as the book went several months past its deadline and when I needed some reassurance that I hadn’t completely jumped the shark. The project editor for the first edition was Kathleen Atkins, who also understood what I was trying to do and provided many pleasant hours of
📄 Page 13
collaboration. My agent at that time was Claudette Moore, who also saw the value of such a book and convinced Microsoft Press to publish it. The technical editor for the first edition was Jim Fuchs, who I remember catching a lot of embarrassing errors. For the second edition, technical reviewers Mark Seemann and Larry O’Brien also caught a few flubs and helped me make these pages better than they would have been otherwise. I thought that I had figured out the difference between “compose” and “comprise” decades ago, but apparently I have not. Correcting errors like that was the invaluable contribution of copy editor Scout Festa. I have always relied on the kindness of copyeditors, who too often remain anonymous strangers but who battle indefatigably against imprecision and abuse of language. Any errors that remain in this book are solely my responsibility. I want to again thank my beta readers of the first edition: Sheryl Canter, Jan Eastlund, the late Peter Goldeman, Lynn Magalska, and Deirdre Sinnott (who later became my wife). The numerous illustrations in the first edition were the work of the late Joel Panchot, who I understand was deservedly proud of his work on this book. Many of his illustrations remain, but the need for additional circuit diagrams inclined me to redo all the circuits for the sake of consistency. (More technical background: These illustrations were generated by a program I wrote in C# using the SkiaSharp graphics library to generate Scalable Vector Graphics files. Under the direction of Senior Content Producer Tracey Croom, the SVG files were converted into Encapsulated PostScript for setting up the pages using Adobe InDesign.) And Finally I want to dedicate this book to the two most important women in my life. My mother battled adversities that would have destroyed a lesser person. She provided a strong direction to my life without ever holding me back. We celebrated her 95th (and final) birthday during the writing of this book. My wife, Deirdre Sinnott, has been essential and continues to make me proud of her achievements, her support, and her love. And to the readers of the first edition, whose kind feedback has been extraordinarily gratifying.
📄 Page 14
Charles Petzold May 9, 2022
📄 Page 15
Pearson’s Commitment to Diversity, Equity, and Inclusion Pearson is dedicated to creating bias-free content that reflects the diversity of all learners. We embrace the many dimensions of diversity, including but not limited to race, ethnicity, gender, socioeconomic status, ability, age, sexual orientation, and religious or political beliefs. Education is a powerful force for equity and change in our world. It has the potential to deliver opportunities that improve lives and enable economic mobility. As we work with authors to create content for every product and service, we acknowledge our responsibility to demonstrate inclusivity and incorporate diverse scholarship so that everyone can achieve their potential through learning. As the world’s leading learning company, we have a duty to help drive change and live up to our purpose to help more people create a better life for themselves and to create a better world. Our ambition is to purposefully contribute to a world where: Everyone has an equitable and lifelong opportunity to succeed through learning. Our educational products and services are inclusive and represent the rich diversity of learners. Our educational content accurately reflects the histories and experiences of the learners we serve. Our educational content prompts deeper discussions with learners and motivates them to expand their own learning (and worldview). While we work hard to present unbiased content, we want to hear from you about any concerns or needs with this Pearson product so that we can investigate and address them.
📄 Page 16
Please contact us with concerns about any potential bias at https://www.pearson.com/report-bias.xhtml.
📄 Page 17
Chapter One Best Friends You’re 10 years old. Your best friend lives across the street. The windows of your bedrooms actually face each other. Every night, after your parents have declared bedtime at the usual indecently early hour, you still need to exchange thoughts, observations, secrets, gossip, jokes, and dreams. No one can blame you. The impulse to communicate is, after all, one of the most human of traits. While the lights are still on in your bedrooms, you and your best friend can wave to each other from the windows and, using broad gestures and rudimentary body language, convey a thought or two. But more sophisticated exchanges seem difficult, and once the parents have decreed “Lights out!” stealthier solutions are necessary. How to communicate? If you’re lucky enough to have a cell phone at the age of 10, perhaps a secret call or silent texting might work. But what if your parents have a habit of confiscating cell phones at bedtime, and even shutting down the Wi-Fi? A bedroom without electronic communication is a very isolated room indeed. What you and your best friend do own, however, are flashlights. Everyone knows that flashlights were invented to let kids read books under the bed covers; flashlights also seem perfect for the job of communicating after dark. They’re certainly quiet enough, and the light is highly directional and probably won’t seep out under the bedroom door to alert your suspicious folks.
📄 Page 18
Can flashlights be made to speak? It’s certainly worth a try. You learned how to write letters and words on paper in first grade, so transferring that knowledge to the flashlight seems reasonable. All you have to do is stand at your window and draw the letters with light. For an O, you turn on the flashlight, sweep a circle in the air, and turn off the switch. For an I, you make a vertical stroke. But, as you quickly discover, this method is a disaster. As you watch your friend’s flashlight making swoops and lines in the air, you find that it’s too hard to assemble the multiple strokes together in your head. These swirls and slashes of light are just not precise enough. Perhaps you once saw a movie in which a couple of sailors signaled to each other across the sea with blinking lights. In another movie, a spy wiggled a mirror to reflect the sunlight into a room where another spy lay captive. Maybe that’s the solution. So you first devise a simple technique: Each letter of the alphabet corresponds to a series of flashlight blinks. An A is 1 blink, a B is 2 blinks, a C is 3 blinks, and so on to 26 blinks for Z. The word BAD is 2 blinks, 1 blink, and 4 blinks with little pauses between the letters so you won’t mistake the 7 blinks for a G. You’ll pause a bit longer between words. This seems promising. The good news is that you no longer have to wave the flashlight in the air; all you need do is point and click. The bad news is that one of the first messages you try to send (“How are you?”) turns out to require a grand total of 131 blinks of light! Moreover, you forgot about punctuation, so you don’t know how many blinks correspond to a question mark. But you’re close. Surely, you think, somebody must have faced this problem before, and you’re absolutely right. With a trip to the library or an internet search, you discover a marvelous invention known as Morse code. It’s exactly what you’ve been looking for, even though you must now relearn how to “write” all the letters of the alphabet. Here’s the difference: In the system you invented, every letter of the alphabet is a certain number of blinks, from 1 blink for A to 26 blinks for Z. In Morse code, you have two kinds of blinks—short blinks and long blinks. This makes Morse code more complicated, of course, but in actual use it turns out to be much more efficient. The sentence “How are you?” now requires only 32 blinks (some short, some long) rather than 131, and that’s including a code for the question mark.
📄 Page 19
When discussing how Morse code works, people don’t talk about “short blinks” and “long blinks.” Instead, they refer to “dots” and “dashes” because that’s a convenient way of showing the codes on the printed page. In Morse code, every letter of the alphabet corresponds to a short series of dots and dashes, as you can see in the following table. Although Morse code has absolutely nothing to do with computers, becoming familiar with the nature of codes is an essential preliminary to achieving a deep understanding of the hidden languages and inner structures of computer hardware and software. In this book, the word code usually means a system for transferring information among people, between people and computers, or within computers themselves. A code lets you communicate. Sometimes codes are secret, but most codes are not. Indeed, most codes must be well understood because they’re the basis of human communication. The sounds we make with our mouths to form words constitute a code that is intelligible to anyone who can hear our voices and understands the language that we speak. We call this code “the spoken word” or “speech.” Within deaf communities, various sign languages employ the hands and arms to form movements and gestures that convey individual letters of words or whole words and concepts. The two systems most common in North America are American Sign Language (ASL), which was developed
📄 Page 20
in the early 19th century at the American School for the Deaf, and Langue des signes Québécoise (LSQ), which is a variation of French sign language. We use another code for words on paper or other media, called “the written word” or “text.” Text can be written or keyed by hand and then printed in newspapers, magazines, and books or displayed digitally on a range of devices. In many languages, a strong correspondence exists between speech and text. In English, for example, letters and groups of letters correspond (more or less) to spoken sounds. For people who are visually impaired, the written word can be replaced with Braille, which uses a system of raised dots that correspond to letters, groups of letters, and whole words. (I discuss Braille in more detail in Chapter 3.) When spoken words must be transcribed into text very quickly, stenography or shorthand is useful. In courts of law or for generating real- time closed captioning for televised news or sports programs, stenographers use a stenotype machine with a simplified keyboard incorporating its own codes corresponding to text. We use a variety of different codes for communicating among ourselves because some codes are more convenient than others. The code of the spoken word can’t be stored on paper, so the code of the written word is used instead. Silently exchanging information across a distance in the dark isn’t possible with speech or paper. Hence, Morse code is a convenient alternative. A code is useful if it serves a purpose that no other code can. As we shall see, various types of codes are also used in computers to store and communicate text, numbers, sounds, music, pictures, and movies, as well as instructions within the computer itself. Computers can’t easily deal with human codes because computers can’t precisely duplicate the ways in which human beings use their eyes, ears, mouths, and fingers. Teaching computers to speak is hard, and persuading them to understand speech is even harder. But much progress has been made. Computers have now been enabled to capture, store, manipulate, and render many types of information used in human communication, including the visual (text and pictures), the aural (spoken words, sounds, and music), or a combination of both (animations and movies). All of these types of information require their own codes.
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now
Back to List