Digital Electronics A Practical Approach with VHDL William Kleitz Ninth Edition

Similar documents
Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Pearson New International Edition. The 8051 Microcontroller and Embedded Systems Mazidi Mazidi McKinlay Second Edition

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Engineering with Excel. Ronald W. Larsen Fourth Edition

Programmable Logic Controllers. Second Edition

GO! with Microsoft Access 2010 Introductory Gaskin Mclellan Graviett First Edition

Elementary Number Theory. Kenneth H. Rosen Sixth Edition

Advanced Electronic Communications Systems Wayne Tomasi Sixth Edition

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Workplace Communications The Basics George J. Searles Fifth Edition

Technical Communication Today

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Java Foundations John Lewis Peter DePasquale Joe Chase Third Edition

Numerical Analysis Timothy Sauer Second Edition

GLOBAL EDITION. Elementary Surveying. An Introduction to Geomatics FOURTEENTH EDITION. Charles D. Ghilani Paul R. Wolf

Engineering Problem Solving with C++

Calculus & Its Applications Larry J. Goldstein David Lay Nakhle I. Asmar David I. Schneider Thirteenth Edition

Apprenticeships. Functional Skills Level 2 ICT

GLOBAL EDITION. Assembly Language. for x86 Processors SEVENTH EDITION. Kip R. Irvine

Apprenticeships BUSINESS & Functional Skills Level 1 ICT

Heinemann is a registered trademark of Pearson Education Limited

Number representations

Number System. Introduction. Decimal Numbers

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England. and Associated Companies throughout the world

For Tricia: never dull, never boring, the smartest and bravest person I know

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

Apprenticeships CUSTOMER. Functional Skills Level 1 MATHEMATICS

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

CS/EE1012 INTRODUCTION TO COMPUTER ENGINEERING SPRING 2013 HOMEWORK I. Solve all homework and exam problems as shown in class and sample solutions

CMPE223/CMSE222 Digital Logic Design. Positional representation

Numeral Systems. -Numeral System -Positional systems -Decimal -Binary -Octal. Subjects:

Chapter 2: Number Systems

Fundamentals of Programming Session 2

CS & IT Conversions. Magnitude 10,000 1,

Editorial Director, ECS: Publishing Administrator, International Edition: Editor-in-Chief:

MACHINE LEVEL REPRESENTATION OF DATA

Number Systems CHAPTER Positional Number Systems

CHAPTER 2 (b) : AND CODES

Chapter 1. Digital Systems and Binary Numbers

CS 101: Computer Programming and Utilization

Computer Organization

CHAPTER 1 Numerical Representation

THE LOGIC OF COMPOUND STATEMENTS

EE292: Fundamentals of ECE

Chapter 1 Review of Number Systems

Ms Sandhya Rani Dash UNIT 2: NUMBER SYSTEM AND CODES. 1.1 Introduction

Digital Fundamentals

Signed Binary Numbers

Korea University of Technology and Education

COMP Overview of Tutorial #2

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

CO Computer Architecture and Programming Languages CAPL. Lecture 9

FUNDAMENTALS OF DIGITAL CIRCUITS

Numbers and Representations

Moodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS

data within a computer system are stored in one of 2 physical states (hence the use of binary digits)

Digital Systems and Binary Numbers

CS101 Lecture 04: Binary Arithmetic

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

What Is It? Instruction Register Address Register Data Register

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England. and Associated Companies throughout the world

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Introduction to Java Programming Comprehensive Version

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Outline. What Digit? => Number System. Decimal (base 10) Significant Digits. Lect 03 Number System, Gates, Boolean Algebra. CS221: Digital Design

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

BINARY SYSTEM. Binary system is used in digital systems because it is:

Memory Addressing, Binary, and Hexadecimal Review

SE311: Design of Digital Systems

D I G I T A L C I R C U I T S E E

Octal & Hexadecimal Number Systems. Digital Electronics

Thus needs to be a consistent method of representing negative numbers in binary computer arithmetic operations.

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England. and Associated Companies throughout the world

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

User. Application program. Interfaces. Operating system. Hardware

Introduction to Computer Science-103. Midterm

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Chapter 3: Number Systems and Codes. Textbook: Petruzella, Frank D., Programmable Logic Controllers. McGraw Hill Companies Inc.

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Computer Organization and Assembly Language. Lab Session 01

Programming Studio #1 ECE 190

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts. Chapter Overview. Welcome to Assembly Language

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates. Invitation to Computer Science, C++ Version, Third Edition

COMP2121: Microprocessors and Interfacing. Number Systems

CHAPTER 2 Number Systems

How & Why We Subnet Lab Workbook

CHW 261: Logic Design

Transcription:

Digital Electronics A Practical Approach with VHDL William Kleitz Ninth Edition

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world Visit us on the World Wide Web at: www.pearsoned.co.uk Pearson Education Limited 2014 All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without either the prior written permission of the publisher or a licence permitting restricted copying in the United Kingdom issued by the Copyright Licensing Agency Ltd, Saffron House, 6 10 Kirby Street, London EC1N 8TS. All trademarks used herein are the property of their respective owners. The use of any trademark in this text does not vest in the author or publisher any trademark ownership rights in such trademarks, nor does the use of such trademarks imply any affiliation with or endorsement of this book by such owners. ISBN 10: 1-292-02561-1 ISBN 13: 978-1-292-02561-2 British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library Printed in the United States of America

2 Two s-complement Representation The most widely used method of representing binary numbers and performing arithmetic in computer systems is by using the two s-complement method. With this method, both positive and negative numbers can be represented using the same format, and binary subtraction is greatly simplified. All along we have seen representing binary numbers in groups of eight for a reason. Most computer systems are based on 8- or 16-bit numbers. In an 8-bit system, the total number of different combinations of bits is 256 (2 8 ); in a 16-bit system, the number is 65,536 (2 16 ). To be able to represent both positive and negative numbers, the two s-complement format uses the most significant bit (MSB) of the 8- or 16-bit number to signify whether the number is positive or negative. The MSB is therefore called the sign bit and is defined as 0 for positive numbers and 1 for negative numbers. Signed two scomplement numbers are shown in Figure 4. D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 Sign bit (a) D 15 D 14 D 13 D 12 D 11 D 10 D 9 D 8 D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 Sign bit (b) Figure 4 Two s-complement numbers: (a) 8-bit number; (b) 16-bit number. The range of positive numbers in an 8-bit system is 0000 0000 to 0111 1111 (0 to 127). The range of negative numbers is 1111 1111 to 1000 0000 (-1 to -128). In general, the maximum positive number is equal to 2 N - 1-1, and the maximum negative number is -(2 N - 1 ), where N is the number of bits in the number, including the sign bit (e.g., for an 8-bit positive number, 2 8-1 - 1 = 127). A table of two s-complement numbers can be developed by starting with some positive number and continuously subtracting 1. Table 3 shows the signed two s-complement numbers from +7 to -8. Converting a decimal number to two s complement, and vice versa, is simple and can be done easily using logic gates, as we will see later in this chapter. For now, let s deal with 8-bit numbers; however, the procedure for 16-bit numbers is exactly the same. Steps for Decimal-to-Two s-complement Conversion 1. If the decimal number is positive, the two s-complement number is the true binary equivalent of the decimal number (e.g., +18 = 0001 0010). 2. If the decimal number is negative, the two s-complement number is found by (a) Complementing each bit of the true binary equivalent of the decimal number (this is called the one s complement). (b) Adding 1 to the one s-complement number to get the magnitude bits. (The sign bit will always end up being 1.) Team Discussion Try to represent the number 160 10 in two s-complement for an 8-bit system. Why doesn t it work? 277

TABLE 3 Signed Two s-complement Numbers 7 Through 8 Decimal Two s Complement 7 0000 0111 6 0000 0110 5 0000 0101 4 0000 0100 3 0000 0011 2 0000 0010 1 0000 0001 0 0000 0000 1 1111 1111 2 1111 1110 3 1111 1101 4 1111 1100 5 1111 1011 6 1111 1010 7 1111 1001 8 1111 1000 Steps for Two s-complement-to-decimal Conversion 1. If the two s-complement number is positive (sign bit = 0), do a regular binary-to-decimal conversion. 2. If the two s-complement number is negative (sign bit = 1), the decimal sign will be, and the decimal number is found by (a) Complementing the entire two s-complement number, bit by bit. (b) Adding 1 to arrive at the true binary equivalent. (c) Doing a regular binary-to-decimal conversion to get the decimal numeric value. The following examples illustrate the conversion process. Common Misconception As soon as some students see the phrase convert to two s complement, they go ahead with the procedure for negative numbers whether the original number is positive or negative. EXAMPLE 5 Convert +35 10 to two s complement. EXAMPLE 6 True binary = 0010 0011 Two s complement = 0010 0011 Answer Convert -35 10 to two s complement. True binary =0010 0011 One s complement =1101 1100 Two s complement =1101 1101 Answer 278

EXAMPLE 7 Convert 1101 1101 two s complement back to decimal. The sign bit is 1, so the decimal result will be negative. Two s complement =1101 1101 Complement =0010 0010 True binary =0010 0011 Decimal complement = - 35 Answer EXAMPLE 8 Convert -98 10 to two s complement. True binary =0110 0010 One s complement =1001 1101 Two s complement =1001 1110 Answer EXAMPLE 9 Convert 1011 0010 two s complement to decimal. The sign bit is 1, so the decimal result will be negative. Two s complement =1011 0010 Complement =0100 1101 True binary =0100 1110 Decimal complement = -78 Answer Review Questions 4. Which bit in an 8-bit two s-complement number is used as the sign bit? 5. Are the following two s-complement numbers positive or negative? (a) 1010 0011 (b) 0010 1101 (c) 1000 0000 3 Two s-complement Arithmetic All four of the basic arithmetic functions involving positive and negative numbers can be dealt with very simply using two s-complement arithmetic. Subtraction is done by 279

adding the two two s-complement numbers. Thus, the same digital circuitry can be used for additions and subtractions, and there is no need always to subtract the smaller number from the larger number. We must be careful, however, not to exceed the maximum range of the two s-complement number: +127 to -128 for 8-bit systems, and +32,767 to -32,768 for 16-bit systems (+2 N - 1-1 to -2 N - 1 ). When adding numbers in the two s-complement form, simply perform a regular binary addition to get the result. When subtracting numbers in the two s-complement form, convert the number being subtracted to a negative two s-complement number and perform a regular binary addition [e.g., 5-3 = 5 + (-3)]. The result will be a two s-complement number, and if the result is negative, the sign bit will be 1. Work through the following examples to familiarize yourself with the addition and subtraction procedure. EXAMPLE 10 Add 19 + 27 using 8-bit two s-complement arithmetic. 19 = 27 = 0001 0011 0001 1011 0010 1110 = 46 10 EXAMPLE 11 Perform the following subtractions using 8-bit two s-complement arithmetic. (a) (b) (c) (d) (a) 18-7 is the same as 18 + (-7), so just add 18 to negative 7. Note: The carry-out of the MSB is ignored. (It will always occur for positive sums.) The 8-bit answer is 0000 1011. (b) (c) 18-7; 21-13; 118-54; 59-96. +21 = -13 = +118 = -54 = (d) +59 = -96 = +18 = -7 = 0001 0101 1111 0011 0000 1000 = 8 10 0111 0110 1100 1010 0100 0000 = 64 10 0011 1011 1010 0000 1101 1011 = -37 10 0001 0010 1111 1001 0000 1011 = 11 10 280

Review Questions 6. Which of the following decimal numbers cannot be converted to 8-bit two s-complement notation? (a) 89 (b) 135 (c) -107 (d) -144 7. The procedure for subtracting numbers in two s-complement notation is exactly the same as for adding numbers. True or false? 8. When subtracting a smaller number from a larger number in two s complement, there will always be a carry-out of the MSB, which will be ignored. True or false? 4 Hexadecimal Arithmetic* Hexadecimal representation is a method of representing groups of 4 bits as a single digit. Hexadecimal notation has been widely adopted by manufacturers of computers and microprocessors because it simplifies the documentation and use of their equipment. Eight- and 16-bit computer system data, program instructions, and addresses use hexadecimal to make them easier to interpret and work with than their binary equivalents. Hexadecimal Addition ARITHMETIC OPERATIONS AND CIRCUITS Remember, hexadecimal is a base 16 numbering system, meaning that it has 16 different digits (as shown in Table 4). Adding 3 + 6 in hex equals 9, and 5 + 7 equals C. But, adding 9 + 8 in hex equals a sum greater than F, which will create a carry. The sum of 9 + 8 is 17 10, which is 1 larger than 16, making the answer 11 16. TABLE 4 Hexadecimal Digits with Their Equivalent Binary and Decimal Values Hexadecimal Binary Decimal 0 0000 0 1 0001 1 2 0010 2 3 0011 3 4 0100 4 5 0101 5 6 0110 6 7 0111 7 8 1000 8 9 1001 9 A 1010 10 B 1011 11 C 1100 12 D 1101 13 E 1110 14 F 1111 15 * Most scientific calculators perform number base conversions and arithmetic. This allows you to enter binary, octal, decimal, or hexadecimal numbers and perform any of the arithmetic operations. In this chapter we will learn the step-by-step procedures for performing these operations by hand, but as the numbers get more complex it is best to use your calculator for these functions. 281