Docsity

Digital Computer Electronics (Malvino), Notas de estudo de Engenharia Informática

Pré-visualização parcial do texto

Baixe Digital Computer Electronics (Malvino) e outras Notas de estudo em PDF para Engenharia Informática, somente na Docsity!

Digital Computer Electronics Third Edition Albert Paul Malvino, Ph.D. Jerald A. Brown GLENCOE McGraw-Hill New York, New York Columbus, Ohio wWoodland Hills, California Peoria, Illinois This textbook was prepared with the assistance of Publishing Advisory Service LSI circuit photo: Manfred Kage:Peter Amold Inc. To my wife, Joanna, who encourages me to write. And to my daughters, Joanna, Antonia, Lucinda, Patrícia, and Miriam, who keep me young. —A.P.M. “to my wife Vicki dearest friend fellow adventurer love of my life —J.AB. Library of Congress Cataloging-in-Publication Data Malvino, Albert Paul Digital computer electronics * Albert Paul Malvino, Jerald A. Brown. — 3rd ed. Pp em Includes index. ISBN 0-02-800594-5 (hardcover) 1. Electronic digital computers. 2. Microcomputers. 3. Intel 8085 (Microprocessor) |. Brown, Jerald A, Il. Title. TK7888.3.M337 1993 621.39'16-—dc20 92-5895 CIP Digital Computer Etectronies, Third Edition Imprint 1999 Copyright O 1993, 1983 by Glencos/McGraw-Hill. A rights reserved. Copyright O 1983, 1977 by McGraw-Hill, Inc, AIl rights reserved. Printed in the Uniled States of America. Except as permittod under the United States Copyright Act, no part of fhis publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without prior written permission of the publisher. ISBN 0-02-800594-5 Printed in the United States of America. 456789101112 004045 0302010089 CHAPTER 12. SAP-3 195 [2-1 Programming Model 12-2. MOV and MVT 12-3, Arithmetic Instructions [2-4 Increments, Decrements. and Rotates 12-5. Logic Instructions 12-6. Arithmetic and Logic Immediates 127. Jump Instructions 12-8. Extended-Repgister Instructions 12-9. Indirect lostructions 12-10. Stack Instructions Programming Popular Microprocessors 213 CHAPTER 13, INTRODUCTION TO MICROPROCESSORS 213 13-1, Computer Hardware 13-2. Definition of a Microprocessor 13-3. Some Common Uses for Microprocessors 13-4, Microprocessors Featured in This Text 13-5, Access to Microprocessors CHAPTER 14. PROGRAMMING AND LANGUAGES 216 14-1. Relationship between Electronics and Programming 14-2, Programming 14-3. Fundamental Premise l4-4, Flowcharts 14: 14-6. Assembly Language Programming Languages 14-7. Workshests CHAPTER 15. SYSTEM OVERVIEW 224 New Concepts 15-1. Computer Architecture 15-2. Microprocessor Architecture Specific Microprocessor Families 15-3. 6502 Family 15-4, 6800/6808 Family 15-5. 8080/8085:Z80 Family 15-6. 8086/8088 Family CHAPTER 16. DATA TRANSFER INSTRUCTIONS 240 New Concepts 16-1. CPU Control Instructions 16-2. Data Transter Instructions Specific Microprocessor Families 16-3. 6502 Family 6-4. 6800/6808 Family 16-5. 8080/8085/780 Family 16-6, 8086/8088 Family CHAPTER 17. ADDRESSING MODES—I 263 New Concepts 17-1. What is an Addressing Mode”? 17-2. The Paging Concept 17-3. Basic Addressing Modes Specific Microprocessor Families 17-4. 6502 Family W7-5. 6800/6808 Family 17-6. 8080/8085/280 Family 17-7. 8086/8088 Family Éy Contents CHAPTER 18. ARITHMETIC AND FLAGS 270 New Concepts 8-1, Microprocessors and Numbers 18-2. Arilhmetic Instructions 8-3. Flag Instructions Specific Microprocessor Families 18.4 6502 Family 18-5. 6800/6808 Family 18-6. 8080:8085/280 Family 18-7. 8086/8088 Family CHAPTER 19, LOGICAL INSTRUCTIONS 305 New Concepts 19-1. The AND Instruction 19-2, The or Instruction 19-3. The EXCIUSIVE-OR (EOR, XOR5 Instruction [9-4 “The Nor Instruction 19-5. “The NEG (NEGate) Instruction Specific Microprocessur Families 19-7. 6800/6808 Family 19-9. 8086/8088 Family 19-6. 6502 Family 19-8. 8080/8085:Z80 Family CHAPTER 20. SHIFT AND ROTATE INSTRUCTIONS 319 New Concepts 20-1 20-3. An Example Specific Microprocessor Families 20-4, 6502 Family 20-5, 6800:6808 Family 20-6. 8080/8085:Z80 Family 20-7. 8086/8088 Family Rotating 20-2. Shifting CHAPTER 21. ADDRESSING MODES—II 329 New Concepts 21-1. Advanced Addressing Modes Specific Microprocessor Families 21-2. 6502 Family 21-3. 6800/6808 Family 21-4. 8080:8085:Z80 Family 21-5. 8086/8088 Family CHAPTER 22. BRANCHING AND LOOPS 342 New Concepts 22-1, Unconditional Jumps 22-2. Conditional Branching 22-3. Compare and Test Instructions 22-4. Increment and Decrement Instructions 22-5. Nested Loops Specific Microprocessor Families 22-7. 6800/6808 Family 22-9. 8086/8088 Family 22-6. 6502 Family 22-8. B080:8085/280 Family CHAPTER 23. SUBROUTINE AND STACK INSTRUCTIONS 363 New Concepts 23-1. Stack and Stack Pointer 23-2. Branching versus Subroutines 23-3. How Do Subroutines Return? 2 Pushing and Popping Registers Specific Microprocessor Families 23-5. 6502 Family 23-6. 68006808 Family 23-7. 8080:8085/Z80 Family 24-8. 8086/8088 Family PART 4 Microprocessor Instruction Set Tables 379 A. Expanded Table of 8085/8080 and Z80 (8080 Subset) Instructions Listed by Category 381 Mini Table of 8085/8080 and Z80 (8080 Subset) Instructions Listed by Category 410 Condensed Table of 8085/8080 and Z80 (8080) Instructions Listed by Category 415 Condensed Table of 8085/8080 and Z80 (8080 Subset) Instructions Listed by Op Code 417 Condensed Table of 8085/8080 and Z80 (8080 Subset) Instructions Listed Alphabetically by 8085/8080 Mnemonic 419 Condensed Table of 8085/8080 and Z80 (8080 Subset) Instructions Listed Alphabetically by Z80 Mnemonic 421 B. Expanded Table of 6800 Instructions Listed by Category 422 Short Table of 6800 Instructions Listed Alphabetically 434 Short Table of 6800 Instructions Listed by Category 437 Condensed Table of 6800 Instructions Listed by Category 441 Condensed Table of 6800 Instructions Listed Alphabetically 443 Condensed Table of 6800 Instructions Listed by Op Code 444 c. Expanded Table of 8086/8088 Instructions Listed by Category 445 Condensed Table of 8086/8088 Instructions Listed by Category 465 Condensed "Fable of 8086/8088 Instructions Listed Alphabetically 469 D Expanded Table of 6502 Instructions Listed by Category 4 Short Table of 6502 Instructions Listed by Category 478 Condensed Table of 6502 Instructions Listed by Category 480 Condensed Table of 6502 Instructions Listed Alphabetically 48] Condensed Table of 6502 Instructions Listed by Op Code 482 APPENDIXES 485 1. The Analog Interface 2. Binary-Hexadecimal- Decimal Equivalents 3. 7400 Series TTL 4. Pinouts and Function Tables 5, SAP-I Parts List 6. 8085 Instructions 7. Memory Locations: Powers of 2 8. Memory Locations: 16K and SK Intervals 9. Memory Locations: 4K Intervals 10. Memory Locations: 2K Intervals 1. Memory Locations: [K Intervals 12. Programming Models ANSWERS TO ODD-NUMBERED PROBLEMS 513 INDEX 519 Contents U PARTA DIGITAL PRINCIPLES AD 1 D NUMBER SYSTEMS AND CODES Modem computers don't work with decimal numbers. Instead, they process binary numbers, groups of Os and Is. Why binary numbers? Because electronic devices are most reliable when designed for two-state (binary) operation. This chapter discusses binary numbers and other concepts needed to understand computer operation. 1-1 DECIMAL ODOMETER René Descartes (1596-1650) said that the way to learn a new subject is to go from the known to the unknown, from the simple to the complex. Let's try it. The Known Everyone has seen an odometer (miles indicator) in action, When a car is new. its odometer starts with 00000 After 1 mile the reading becomes O0001 Suecessive miles produce 00002, 00003, and so on, up to 00009 A familiar thing happens at the end of the tenth mile. When the units whcel turns from 9 back to O, a tab on this wheel forces the tens wheel to advance by 1. This is why the numbers change to 00010 Reset-and-Carry The units wheel has reset to O and sent a carry to the tens wheel. LeU's call this familiar action reser-and-carry. The other wheels also resct and carry. After 999 miles the odometer shows 00999 What does the next mile do? The units whecl resets and carries, the tens wheel resets and carries, the hundreds wheel rescts and carries, and thc thousands whec] advances by 1, to get 01000 Digits and Strings The numbers on each odometer whec] are called digits. The decimal number system uses ten digits, O through 9. In a decimal odometer, cach time the units wheel runs out of digits, it resets to O and sends a carry to the tens wheel. When the tens wheel runs out of digits, it resets to O and sends a carry to the hundreds wheel. And so on with the remaining whecls. One more point. À string is a group of characters (cither letters or digits) written one after another. For instance, 734 is a string of 7, 3, and 4. Similarly, 2CBA is a string of2,C,8.andA. 1-2 BINARY ODOMETER Binary means two. The binary number system uses only two digits, O and 1. All other digits (2 through 9) are thrown away. In other words, binary numbers arc strings of Os and Is. An Unusual Odometer Visualize an odometer whose wheels have only two digits, U and 1. When each wheel turns, it displays 0, then 1, then 1 back to 0), and the cycle repeats. Because each wheel has only two digits, we call this device a binary odometer. Tn a car a binary odometer starts with 0000 (zero) After 1 mile, it indicates 000) tone) The next mile forces the units wheel to reset and carry; so the numbers change to 0010 (two) The third mile results in 0011 (three) What happens after 4 miles? The units wheel resets and carries, the second wheel resets and carries, and the third wheel advances by 1. This gives 0100 (four) Suecessive miles produce OIL (five) oT10 (six) on (seven) After 8 miles, the units wheel resets and carries, the second wheel resets and carries, thg third wheel resets and carries, and the fourth wheel advances by 1. The result is 1000 (eight) The ninth mile gives 1001 (nine) and the tenth mile produces 1010 (ten) (Try working out a few more readings on your own.) You should have the idea by now. Each mile advances the units wheel by 1. Whenever the units wheel runs out of digits, it resets and carries. Whenever the second wheel runs out of digits, it resets and carries. And so for the other wheels. Binary Numbers A binary odometer displays binary numbers, strings of Os and Is. The number 0001 stands for 1, OD10 for 2, 0011 2 Digital Computer Electronics for 3, and so forth. Binary numbers are long when large amounts ate involved. For instance. TOJOLO represents decimal 42. As another example, [1110000115 stands for decimal 3,855, Computer circuits are like binary odometers; they count and work with binary numbers. Therefore, you have to learn to count with binary numbers, to convert them to decimal numbers, and to do binary arithmetic. Then you will be ready to understand how computers operate. A final point. When a decimal odometer shows 0036, we can drop the leading Os and read the number as 36. Similarly, when a binary odometer indicates 0011, we can drop the leading Os and read the number as 11. With the leading Os omitted. the binary numbers are 0, 1, 10, 11, 100, 101, and so on, To avoid confusion with decimal numbers, read the binary numbers like this: zero, one, one- Z£T0, One-one, one-zero-zero, onc-zero-one, etc. 1-3 NUMBER CODES People used to count with pebbles. The numbers 1, 2, 3 looked like O. Larger numbers were worse: seven appeared as O 0. Codes From the earliest times, people havc been creating codes that allow us to think, calculate, and communicate. The decimal numbers are an example of a code (see Table 1-1). T's an old idea now, but at the time it was as revolutionary; 1 stands for 0, 2 for 00,3 for 0 and so forth. Table 1-1 also shows the binary code. 1 stands for 0, 10 for 00, 1] for 000, and soon. A binary number anda decimal number arc equivalent if each represents the same amount of pebbles. Binary 10 and decimal 2 are equivalent because each represents 00. Binary 101 and decimal 5 arc equivalent because each stands for O o. TABLE 1-1. NUMBER CODES Decimal Pebbles Binary 0 None A) 1 1 2 10 3 n 4 100 5 101 6 no 7 11 8 1000 9 1001 An analogy may help. A phonograph is like hardware and records are like software. The phonograph is useless without records. Furthermore, the music you get depends on the record you play. A similar idea applies to computers. A computer is the hardware and programs are the software. The computer is useless without programs. The program stored in the computer determines what the computer will do; change the program and the computer processes the data in a different way. Transistors Computers use integrated circuits (ICs) with thousands of transistors, either bipolar or MOS. The parameters (Bu, Tcos Em etc.) can vary more than 50 percent with temperature change und from one transistor to thc next. Yet these computer [Cs work remarkably well despite the transistor variations. How is it possible? The answer is two-state design, using only two points on the load line of each transistor. For instance, the common two-state design is the cutoff-saturation approach; cach transistor is forced to operate at either cutoff or saturation. When a transistor is cut off or saturated, parameter variations have almost no effect. Because of this, it's possible to design reliable two-state circuits that are almost independent of temperature change and transistor variations. Transistor Register Here”s an example of two-stute design. Figure 1-2 shows a wansistor register. (A register is a string of devices that store data.) The transistors on the left are cut off because the input base voltages are O V. The dark shading symbolizes the cutoff condition. The two transistors on the right have base drives of 5 V. The transistors operate at either saturation or cutoff. A base voltage of O V forces each transistor to cut off, while a base voltage of 5 V drives it into saturation. Because of this two-state action, cach transistor stays in a given state until the base voltage switches it to the opposite state. Another Code Two-state operation is universal in digital electronics. By deliberate design, all input and output voltages are cither low or high. Here's how binary numbers come in: low voltage represents binary O. and high voltage stands for binary t. In other words, we use this code: Voltage Binary Low o High 1 For instance, the base voltages of Fig. 1-2 are low-low- high-high, or binary 0011. The collector voltages are high- high-low-low, or binary 1100. By changing the base voltages we can store any binary number from 0000 to 11 11 (decimal Oto 15). Bit Bir is an abbreviation for binary digit. A binary number like 1100 has 4 bits: 110011 has 6 bits; and 11001100 bas 8 bits. Figure 1-2 is a 4-bit register. To store lurger binary numbers, it needs more transistors. Add two transistors and you get a 6-bit register. With four more transistors, you'd have an 8-bit register. Nonsaturated Circuits Don't get the idea that all two-state circuits switch between cutoff and saturation. When a bipolar transistor is heavily saturated, extra carriers are stored in the base region. If the base voltage suddenly switches [rom high to low, the transistor cannot come out of saturation until these extra carriers have a chance to leave the base region. The time it takes for these carriers to leave is called the saruration detay time ty. Typically, t, is in nanoseconds. Tn most applications the saturation delay time is too short to matter. But some applications require the fastest possible ov Fig. 1.2 Transistor register 4 Digital Computer Electronics +5V 1k8 1kM ov ov (Approx.) (Approx.) 1082 10k2 +5V switching time, To get this maximum speed, designers have come up with circuits that switch from cutoff (or near cutoff) to a higher point on the load line (but short of saturation). These nonsaturated circuíts rely on clamping diodes or heavy negative feedback to overcome transistor variations. Remember this: whether saturated or nonsaturated circuits are used, the transistors switch between distinct points on the load line. This means that all input and output voltages arc easily recognized as low or high, binary O or binary 1. ss2e assa Fig. 1:3 Core register. Magnetic Cores Early digital computers used magnetic cores to store data. Figure 1-3a shows a 4-bit core register. With the right- hand rule, you can see that conventional current into a wire produces a clockwise flux; reversing the current gives a counterclockwise flux. (The same result is obtained if electron-flow is assumed and the left-hand rule is used.) The cores have rectangular hysteresis loops: this means that flux remains in a core even though the magnetizing current is removed (see Fig. 1-3h). This is why a core register can store binary data indefinitely. For instance, let's use the following code: Flux Binary Counterclockwise 0 Clockwise 1 Then, the core register of Fig. 1-3b stores binary 1001, equivalent to decimal 9. By changing the magnetizing currents in Fig. 1-34 we can change the stored data. To store larger binary numbers, add more cores. Two cores added to Fig. 1-3a result in a 6-bil register: four more cores give an 8-bit register. The memory is one of the main parts of a computer. Some memories contain thousands of core registers. These registers store the program and data needed to run the computer. Other Two-State Examples The simplest example of a two-state device is the on-off switch. When this switch is closed, it represents binary |; when it's open, it stands for binary O. Punched cards are another example of the two-state concept. A hole in a card stands for binary 1, the absence of a hole for binary O. Using a prearranged code, à card- punch machine with a keyboard can produce a stack of cards containing the program and data needed to run a computer. Magnetic tape can also store binary numbers. Tape recorders magnetize some points on the tape (binary 1), while leaving other points unmagnetized (binary 0). By a prearranged code, a row of points represents either a coded instruction or data. In this way, a recl of tape can store thousands of binary instructions and data for later use in à computer. Even the lights on the contro! panel of a large computer are binary; a light that's on stands for binary 1, and one that's off stands for binary O. In a 16-bit computer, for instance, a row of 16 lights allows the operator to see the binary contents in different computer registers. The operator can then monitor the overall operation and, when necessary, troubleshoot. In summary, switches, transistors, cores, cards, tape, lights, and almost all other devices uscd with computers are based ou two-state operation. This is why we are forced to use binary numbers when analyzing computer action. EXAMPLE 1-3 Figure 1-4 shows a strip of magnetic tape. The black circles are magnetized points and the white circles unmagnetized points. What binary number does each horizontal row represent? Fig. 1-4 Binary numbers on magnetic tape, SOLUTION The tape stores these binary numbers: Row 00001111 Row 5 NIGOTO Row 2 LOO0O110 Row 6 01001001 Row 3 TOTO Row 7 NOOHOL Row d 00110001 Chapter 1 Number Systems and Codes 5 NO, = 13 HAOIOL = 1176 In this book we will use subscripts when necessary for clarity. 1-6 MICROPROCESSORS What is inside a computer? What is à microprocessor? What is a microcomputer? Computer The five main sections of a computer arc input, memory. arithmetic and logic, control, and output. Here is a brief description of each. Input This consists of all the circuits needed to get programs and data into the computer. In some computers the input section includes a typewriter keyboard that converts letters and numbers into strings of binary data. Memory This stores the program and data before the computer run begins. It also can store partial solutions during a computer run, similar to the way we use a scratchpad while working out a problem. Control This is the computer's center of gravity, analo- gous to the conscious part of the mind. The contro] section directs the operation of all other sections. Like the conductor of an orchestra, it tells the other sections what to do and when to do it. Arithmetic and logic This is the number-crunching sec- tion of the machine. It can also make logical decisions. With control teiling it what to do and with memory feeding it data, the arithmetic-logic unit (ALU) grinds out answers to number and logic problems. Output This passes answers and other processed data to the outside world. The output section usually includes a video display to allow the user to see the processed data. Microprocessor The control section and the ALU are often combined physicaliy into a single unit called the central processing unit (CPU), Furthermore, it's convenient to combine the input and output sections into a single unit called the input- outpur (IO) unit. In earlier computers, the CPU, memory, and O unit filled an entire room. With the advent of integrated circuits, the CPU, memory, and PO unit have shrunk dramatically. Nowadays the CPU can be fabricated on a single semiconductor chip called a microprocessor. In other words, a microprocessor is nothing more than a CPU on a chip. Likewise, the LO circuits and memory can be fabricated on chips. In this way. the computer circuits that once filled a room now fit on a few chips. Microcomputer As the name implies, a microcomputer is a small computer. More specifically, a microcomputer is à computer that uses a microprocessor for its CPU. The typical microcomputer has threc kinds of chips: microprocessor (usually one chip), memory (several chips), and O (one or more chips). If a small memory is acceptable, a manufacturer can fabricate all computer circuits on a single chip. For instance, the 8048 from Intel Corporation is a one-chip microcomputer with an 8-bit CPU, 1,088 bytes of memory, and 27 VO lines. Powers of 2 Microprocessor design started with 4-bit devices, then evolved to 8- and 16-bit devices. In our later discussions of microprocessors, powers of 2 keep coming up because of the binary nature of computers. For this reason, you should study Table 1-3. It lists the powers of 2 encountered in microcomputer analysis. As shown, the abbreviation K stands for 1,024 (approximately 1,000). Therefore, IK means 1,024, 2K stands for 2,048, 4K for 4,096, and so on. Most personal microcomputers have 640K (or greater) memories that can store 655,360 bytes (or more). TABLE 1-3. POWERS OF 2 Powers of 2 Decimal equivalent Abbreviation ” L 2 2 22 4 2 8 x 16 pal KV) 2 [o 2” 128 pal 256 ” 512 21 1,024 1K 2! 2,048 2K 212 4,096 4K 213 8,192 8K 214 16,384 I6K 2 32,768 32K 216 65,536 64K * The abbreviations IK, 2K. and so on, became established before K- for kito- was in common use. Retaining the capital K serves as a uscful reminder that K only approximates 1,000. Chapter 1 Number Systems and Codes 7 1-7 DECIMAL-TO-BINARY CONVERSION Next, you need to know how to convert from decimal to binary. After you know how it's done, you will be able to understand how cireuits can be built to convert decimal numbers into binary numbers. Double-Dabble Double-dabble is a way of converting any decimal number to its binary equivalent. It requires successive division by 2, writing down each quotient and its remainder. The remainders are the binary equivalent of the decimal number. The only way to understand the method is to go through an example, step by step. Here is how to convert decimal 13 to its binary equivalent. Step 1. Divide 13 by 2, writing your work like this: 6 1 > (first remainder) 2313 The quotient is 6 with a remainder of 1. Step 2. Divide 6 by 2 to get 3 0 — (second remainder) 256 1 2)13 This division gives 3 with a remainder of 0, Step 3. Again you divide by 2: 1 1> (third remainder) 2)3 0 256 1 27383 Here you get a quotient of 1 and a remainder of 1. Step 4. One more division by 2 gives Read down 01 2jJ1 1 2)3 0 2j6 1 2)13 8 Digital Computer Electronics In this final division, 2 does not divide into 1; therefore, the quotient is O with a remainder of 1. Whenever you arrive at a quotient of O with a remainder of 1, the conversion is finished. The remainders when read downward give the binary equivalent. In this example, binary 1101 is equivalent to decimal 13. Double-dabble works with any decimal number. Pro- gressively divide by 2, writing each quotient and its remainder. When you reach a quotient of O and a remainder of 1, you are finished; the remainders read downward are the binary equivalent of the decimal number. Streamlined Double-Dabble There's no need to keep writing down 2 before each division because you're always divíding by 2. From now on, here's how to show the conversion of decimal 13 to its binary equivalent: dado EXAMPLE 1-4 Convert decimal 23 to binary. SOLUTION The first step in the conversion looks like this: Wa 2)23 After all divisions, the finished work looks like this: asas 1 2)23 This says that binary 10111 is equivalent to decimal 23. 1-9 HEXADECIMAL-BINARY CONVERSIONS After you know the equivalences of Table |-4, you can mentally convert any hexadecimal string to its binary equivalent and vice versa. Hexadecimal to Binary To convert a hexadecimal number to a binary number, convert each hexadecimal digit to its 4-bit equivalent, using Table 1-4. For instance, here's how 9AF converts to binary: 9 A F Vo bo 1001 1010 HI As another example, CSE2 converts like this: Cos E 2 Dolo bos 1100 0101 10 0010 Incidentally, for casy reading it's common practice to leave a space between the 4-bit strings. For example, instead of writing CSE2, = 1100010111100010, we can write CSE2Z, = 1100 0101 1110 0010, Binary to Hexadecimal To convert in the opposite direction, from binary to hexadecimal, you again use Table 1-4. Here are two examples. The byte 1000 1100 converts as follows: 1000 1100 vo 8 c The 16-bit number 1140 1000 1101 0110 converts like this: 110 1000 1101 010 Lodo doq E 8 Dé In both these conversions, we start with a binary number and wind up with the equivalent hexadecimal number. ÃO Digital Computer Electronics EXAMPLE 1-5 Solvc the following equation for x: Xs = 1141 11154 1111 1111, SOLUTION This is the same as asking for the hexadecimal equivalent of binary 1111 1111 1111 1111. Since hexadecimal F is equivalent to 1111, x = FFFF. Theretore, FFFF;, = MT AMEITITT, EXAMPLE 1-6 As mentioned carlier, the memory contains thousands of registers (core or semiconductor) that store the program and data needed for a computer run. These memory registers are known as memory locations. A typical microcomputer may have up to 65,536 memory locations, each storing 1 byte. Suppose the first 16 memory tocations contain these bytes: 0011 1100 1100 1101 0101 0111 0010 1900 1111 0001 0030 1010 1101 0100 0100 0000 0111 0111 1100 0011 1000 0100 0010 1000 0010 0001 0011 1010 GO11 LITO 0001 1111 Convert these bytes to their hexadecimal equivalents. SOLUTION Here are the stored bytes and their hexadecimal equivalents: Memory Contents Hex Equivalents 0011 1100 3€ 1100 1101 cD 0101 0111 57 OOLO 1000 28 1111 0001 Fi 0010 1010 2A 1101 0100 D4 0100 0000 40 0311 0111 ” 1100 0011 c3 1000 0100 84 G010 1000 28 0010 0601 2a 0011 1010 3A 0011 1110 3E 0001 1111 1F What's the point of this example? When talking about the contents of a computer memory, we can use either binary numbers or hexadecimal numbers. For instance, we can say that the first memory location contains QO11 1100, or wc can say that it contains 3C. Either string gives the same information. But notice how much casier it is to say, write, and think 3C than it is to say, write, and think 0011 1100. In other words, hexadecimal strings are much easier for people to work with. This is why everybody working with microprocessors uses hexadecimal notation to represent particular bytes. What we have just done is known as chunking. replacing longer strings of data with shorter ones. At the first memory location we chunk the digits 0011 1LOO into 3C. At the second memory location we chunk the digits 1100 1101 into CD, and so on. EXAMPLE 1-7 The typical microcomputer has a typewriter keyboard that allows you to enter programs and data; a video screen displays answers and other information. Suppose the video screen of a microcomputer displays the hexadecimal contents of the first eight memory locations as A7 28 c3 19 SA ap 2C F8 What are the binary contents of the memory locations” SOLUTION Convert from hexadecimal to binary to get 1010 6111 00140 1000 1100 0011 0001 1001 0101 1010 0100 1101 BOI1O 1100 H11 1000 The first memory location stores the byte 1010 0111, the second memory location stores the byte 0010 1000, and so om. This cxample emphasizes a widespread industrial prac- tice. Microcomputers are programmed to display chunkcd data, often hexadecimal. The user is expected to know hexadecimal-binary conversions. In other words, a computer manufacturer assumes that you know that A7 represents 1010 0111, 28 stands for 0010 1000, and so on. One more point. Notice that each memory location in this example stores 1 byte. This is typical of first-generation microcomputers because they use 8-bit microprocessors. 1-10 HEXADECIMAL-TO-DECIMAL CONVERSION You often need to convert a hexadecimal number to its decimal equivalent. This section discusses methods for doing it. Hexadecimal to Binary to Decimal One way to convert from hexadecimal to decimal is the two-step method of converting from hexadecimal to binary and then from binary to decimal, For instance, here's how to convert hexadecimal 3€C to its decimal equivalent. Step 1. Convert 3€ to its binary equivalent: 3 c b b 0011 1100 Step 2. Convert 0011 1100 to its decimal equivalent: 0 0 1/1 1 00 128 44 32 16 8 Z 1>60 sm Therefore, decimal 60 is equivalent to hexadecimal 3C. As an equation, 3Cj = 00114 1100, = 604 Positional-Notation Method Positional notation is also used with hexadecimal numbers because cach digit position has a weight. Since 16 digits are used, the weights are the powers of 16. As shown in Chapter 1 Number Systems and Codes 11 EXAMPLE 1-8 Convert hexadecimal 7E to its decimal equivalent. SOLUTION EXAMPLE 1-9 Convert decimal 141 to hexadecimal. SOLUTION When converting only a single byte, all you are dealing with is the lower byte. With Appendix 2, look up 7E and its LB decimal equivalent to get TE > 126 In other words, Appendix 2 can be used to convert single bytes to their decimal equivalents (LB decimal) or double bytes to their decimal equivalents (UB decimal + LB decimal). 1-11 DECIMAL-TO-HEXADECIMAL CONVERSION One way to perform decimal-to-hexadecimal conversion is to go from decimal to binary then to hexadecimal. Another way is hex-dabble. The idea is to divide successively by 16, writing down the remainders. (Hex-dabble is like double- dabble except that 16 is used for the divisor instead of 2.) Here's an example of how to convert decimal 2,479 into hexadecimal form. The first division is 154 15 F 16)2,479 The next step is 9 IA 154 15 16 12,479 The tinal step is Read down o 99 j9 10 A 154 15 E 16 )2,479 Notice how similar hex-dabble is to double-dabble. Also, remainders greater than 9 have to be changed to hexadecimal digits (10 becomes A, 15 becomes F, etc.). If you prefer, use Appendix 2 to look up the decimal- hexadecimal! equivalents. The next two examples show how. Whenever the decimal number is between O and 255, all you have to do is look up the decimal number and its hexadecimal equivalent. With Appendix 2. you can see at a glance that 8D <— Id EXAMPLE 1-10 Convert decimal 36,020 to its hexadecimal equivalent. SOLUTION 1f the decimal number is between 256 and 65,535, you need to proceed as follows. First, locate the largest UB decimal that is less than 36,020. In Appendix 2, the largest UB decimal is UB decimal = 35,840 which has a hexadecimal equivalent of 8C — 35,840 This is the upper byte. Next, subtract the UB decimal from the original decimal number: 36,020 — 35,840 = 180 The difference 180 has a hexadecimal equivalent B4 — 180 This is the lower byte. By combining the upper and lower bytes, we get the complete answer: 8CB4. This is the hexadecimal equivalent of 36,020. After a little practice, you will find Appendix 2 to be one of the fastest methods of decimal-hexadecimal conver- sion. 1-12 BCD NUMBERS A nibble is a string of 4 bits. Binary-coded-decimal (BCD) numbers express each decimal digitas a nibble. For instance, decimal 2,945 converts to a BCD number as follows: Chapter 1 Number Systems and Codes 13 2 9 4 5 Lobo pod 0010 1001 0100 O101 As you see, each decimal digit is coded as a nibble. Here's another example: 9,863, converts like this: 9 8 6 3 Vo Lo LoL IG01 1000 OLHO 0011 Therefore, 1001 1000 0110 001] is the BCD equivalent of 9,863. The reverse conversion is similar. For instance, 0010 1000 0111 0100 converts as follows: GIO 1000 OL 0100 Loo Vos 2 8 7/4 Applications BCD numbers are useful whercver decimal information is transferred into or out of a digital system. The circuits inside pocket calculators, for example, can process BCD numbers because you enter decimal numbers through the keyboard and see decimal answers on the LED or liquid- crystal display. Other examples of BCD systems are elec- tronic counters, digital voltmeters, and digital clocks; their circuits can work with BCD numbers. BCD Computers BCD numbers have limited value in computers. A few early computers processed BCD numbers but were slower and more complicated than binary computers. As previously mentioned, a computer is more than a number cruncher because it must handle names and other nonnumeric data. In other words, a modem computer must be able to process alphanumerics (alphabet letters, numbers, and other sym- bols). This why modem computers have CPUs that process binary numbers rather than BCD numbers. Comparison of Number Systems Table 1-5 shows the four number systems we have discussed. Each number system uses strings of digits to represent quantity. Abovc 9, equivalent strings appear different. For instance, decimal string 128, hexadecimal string 80, binary string 1000 0000, and BCD string 0001 0010 1000 are equivalent because thcy represent the same number of pebbles. Machines have to use long strings of binary or BCD numbers, but people prefer to chunk the data in cither decimal or hexadecimal form, As long as we know how to 14 Digital! Computer Electronics TABLE 1-5, NUMBER SYSTEMS Decimal Hexadecimal Binary BCD 0 o) OG0O UO0O 0000 0000 0000 1 1 0000 0001 0000 0000 000 2 2 0000 0010 0000 0000 DOL0 3 3 0000 0011 0000 0000 001 + 4 4 0000 0100 0000 0000 0100 5 5 0000 0101 0000 0000 010% 6 6 0000 0110 0000 0000 0110 7 7 0000 0111 0000 0000 0111 8 8 OD0O 1000 0000 0000 1000 9 9 0000 100? 0000 0000 1001 10 A GO0O 1010 0000 0001 0000 u B 0000 1011 0000 0001 0001 2 c 0000 1100 0000 0001 0010 13 D 0000 1101 0000 000! 0011 lá E 0000 1110 0000 0001 0100 15 F 0000 1111 0000 0001 0101 16 10 0001 0000 0000 0001 0110 32 20 0010 0000 0000 011 0010 4 40 0100 0000 0000 0110 0100 128 so 1000 0000 000! 0010 1000 255 FF ti JUL Q010 0101 0101 convert from one number system to the next, we can always get back to the ultimate meaning, which is the number of pebbles being represented. 1-13 THE ASCII CODE To get information into and out of a computer, we need to use numbers, letters, and other symbols. This implies some kind of alphanumeric code for the I/O unit of a computer. At one time, every manufacturer had a different code, which led to all kinds of confusion. Eventually. industry settled on an input-output code known as the American Standard Code for Information Interchange (abbreviated ASCID. This code allows manufacturers to standardize VO hardware such as keyboards, printers, video displays. and so on. The ASCII (pronounced ask'-ee) code is a 7-bit code whose format (arrangement) is XXX KKK 1Xo where cach X isa O ora |, For instance, the letter A is coded as 1000001 Sometimes, a space is inscrted for easicr reading: 100 0001