Theory of Logic Circuits. Laboratory manual. Exercise 6

Similar documents
COMBINATIONAL CIRCUITS

The string of digits in the binary number system represents the quantity

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Binary Adders: Half Adders and Full Adders

CSI 333 Lecture 1 Number Systems

Chapter 1: Digital Systems and Binary Numbers

NUMBER SYSTEMS. 1.1 Introduction

EXPERIMENT 4. Parallel Adders, Subtractors, and Complementors

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Number Representation

Computer Science 281 Binary and Hexadecimal Review

Useful Number Systems

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Base Conversion written by Cathy Saxton

Number Systems and Radix Conversion

COMPSCI 210. Binary Fractions. Agenda & Reading

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

Number and codes in digital systems

BINARY CODED DECIMAL: B.C.D.

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

2011, The McGraw-Hill Companies, Inc. Chapter 3

Lecture 2. Binary and Hexadecimal Numbers

Let s put together a Manual Processor

Sistemas Digitais I LESI - 2º ano

CPEN Digital Logic Design Binary Systems

DEPARTMENT OF INFORMATION TECHNLOGY

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

NUMBER SYSTEMS. William Stallings

Today s topics. Digital Computers. More on binary. Binary Digits (Bits)

Lecture 11: Number Systems

Chapter 4 Register Transfer and Microoperations. Section 4.1 Register Transfer Language

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Chapter 2. Binary Values and Number Systems

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Systems I: Computer Organization and Architecture

Gates, Circuits, and Boolean Algebra

Binary Numbers. Binary Octal Hexadecimal

Positional Numbering System

1. True or False? A voltage level in the range 0 to 2 volts is interpreted as a binary 1.

Chapter 4: Computer Codes

Theory of Logic Circuits. Laboratory manual. Exercise 3

Binary, Hexadecimal, Octal, and BCD Numbers

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

=

Two's Complement Adder/Subtractor Lab L03

Section 1.4 Place Value Systems of Numeration in Other Bases

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

2 Number Systems. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

APPENDIX B. Routers route based on the network number. The router that delivers the data packet to the correct destination host uses the host ID.

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

An Efficient RNS to Binary Converter Using the Moduli Set {2n + 1, 2n, 2n 1}

CS321. Introduction to Numerical Methods

Binary Numbering Systems

Systems I: Computer Organization and Architecture

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Solution for Homework 2

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

YOU MUST BE ABLE TO DO THE FOLLOWING PROBLEMS WITHOUT A CALCULATOR!

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

Experiment # 9. Clock generator circuits & Counters. Eng. Waleed Y. Mousa

Decimal Number (base 10) Binary Number (base 2)

Unsigned Conversions from Decimal or to Decimal and other Number Systems

FORDHAM UNIVERSITY CISC Dept. of Computer and Info. Science Spring, Lab 2. The Full-Adder

3. Convert a number from one number system to another

Understanding Logic Design

DB19. 4-Bit Parallel Adder/ Subtractor. Digital Lab Experiment Board Ver. 1.0

Lecture 8: Binary Multiplication & Division

5 Combinatorial Components. 5.0 Full adder. Full subtractor

Logic Reference Guide

Counters and Decoders

HOMEWORK # 2 SOLUTIO

Design and Development of Virtual Instrument (VI) Modules for an Introductory Digital Logic Course

MATH-0910 Review Concepts (Haugen)

PREPARATION FOR MATH TESTING at CityLab Academy

CHAPTER 5 Round-off errors

Upon completion of unit 1.1, students will be able to

MEP Y9 Practice Book A

Circuits and Boolean Expressions

Chapter 7 Lab - Decimal, Binary, Octal, Hexadecimal Numbering Systems

Digital Logic Design. Introduction

Integer Operations. Overview. Grade 7 Mathematics, Quarter 1, Unit 1.1. Number of Instructional Days: 15 (1 day = 45 minutes) Essential Questions

United States Naval Academy Electrical and Computer Engineering Department. EC262 Exam 1

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 TUTORIAL OUTCOME 2 Part 1

VHDL Test Bench Tutorial

Digital Electronics Detailed Outline

Digital Logic Design. Basics Combinational Circuits Sequential Circuits. Pu-Jen Cheng

Binary Representation

Lecture 4: Binary. CS442: Great Insights in Computer Science Michael L. Littman, Spring I-Before-E, Continued

Systems I: Computer Organization and Architecture

Logic in Computer Science: Logic Gates

Transcription:

Zakład Mikroinformatyki i Teorii Automatów Cyfrowych Theory of Logic Circuits Laboratory manual Exercise 6 Selected arithmetic switching circuits 2008 Tomasz Podeszwa, Piotr Czekalski (edt.)

1. Number systems and representations There are many different numbers systems all over the world. Most of them are weight-positional systems, where value of number s each digit depends on both value of digit and it s position in a sequence of symbols. Therefore, during labs there will be implemented circuits working with these number systems (exactly: working with numbers by a radix 2 called also binary system). 1.1. Weighted-positional number systems In weighted-positional number systems each number is represented by sequence of digits followed by a comma or period (which depends on country). The value of a particular digit in this number depends on its position in the sequence of digits relative to a radix point. For example number N in weighted-positional system by base r can be converted to equivalent decimal number using the following polynomial function: (N) r = (d j d j-1 d j-2...d 3 d 2 d 1 d 0.d -1 d -2 d -3...d -k ) r = d j r j +d j-1 r j-1 +d j-2 r j-2 +...+d 3 r 3 +d 2 r 2 +d 1 r 1 +d 0 r 0 +d -1 r -1 +d -2 r -2 d -3 r -3 +...+d -k r -k = (M) 10 Note: 0 d i r-1 Besides decimal, the most popular systems are also binary (base 2), octal (base 8) and hexadecimal (base 16). 1.2. Converting from decimal to other number systems One of the methods used to convert from decimal to other number system is repeated radix division technique for integers and multiplication technique for fractions. During conversion process we must first break number into integer and fraction part. Next the integer part is repeatedly divided by new base r and remainders are written in reverse order (from last to first) to obtain integer part of destination number. Also fractional part is processed by repeatedly multiplying by new base r and every integer number obtained during each step is written in order that they appear. For example converting number (121.375) 10 into number by base 2 we obtain: 121:2 = 60 r=1 60:2=30 r=0 30:2=15 r=0 15:2=7 r=1 7:2=3 r=1 3:2=1 r=1 1:2=0 r=1 and for fraction: 0.375*2=0.75 r=0 0.75*2=1.5 r=1 0.5*2=1 r=1 so number (119.375) 10 = (1111001.011) 2 Page 2 of 8

1.3. Number representations So far only positive numbers were presented. As in decimal, also in other systems we have to present both positive (represented with + sign) and negative (represented with - sign) values. This notation is called sign magnitude. Computers are generally not designed to interpret a plus or minus sign, so often the most significant bit is reserved for sign (0 means +, 1 means - ). During most operations computer circuits must first check sign bits of arguments and (according to their values) perform appropriate operations. Positive and negative numbers can also be expressed by two other number representations. These are the diminished radix complement (DRC) or (r-1) s complement representation, and radix complement (RC) or r s complement representation. The (r-1) s complement of a number N is defined by the relationship, r i -r -f -N, where N is the number to be negated, r is the radix, i is the number of integer digits, and f is the number of fractional digits. To obtain 1 s complement of a binary number N, simply complement each digit of the number. The r s complement of a number N is defined by the relationship r i -N, where N is the number to be negated, r is the radix, i is the number of integer digits, and f is the number of fractional digits. To obtain 2 s complement of a binary number N, simply first obtain 1 s complement of N and then add 1 at the least significant bit. Notice that positive numbers in all representations presented above are expressed in the same way. Example (r=2): Let (A) 2 =(11010011.01101) 2 then we should use at least 9 positions for integer and 5 positions for fraction, so (A) 2 =(011010011.01101) 2 1. Using sign-magnitude representation: (-A) 2 =(111010011.01101) 2 2. Using 1's complement representation: (-A) 2 =(100101100.10010) 2 3. Using 2s complement representation: (-A) 2 =(100101100.10011) 2 To convert negative numbers into positive, one should perform exactly the same operation as above. 2. Arithmetic operations The operations of addition, subtraction, multiplication, and division can be carried out in exactly the same manner with binary numbers as they are with decimal numbers. When number is in 1 s or 2 s complement representation, computer needs to use only Adder circuit and Complementor circuit to obtain the result of all of these operations. When we need to perform a subtraction operation, first subtrahend is converted into 1 s or 2 s complement and next simply added to minuend. Notice that when binary numbers to be added are in a 2 s complement representation the carry occurring from the sign bit position is simply ignored, while in a 1 s complement representation this carry is added back to the least significant bit of the sum. Since multiplication can always be performed by repeated addition, and division can be repeated subtraction, the addition process can perform all four arithmetic operations. Page 3 of 8

2.1. Binary adders Binary adder is a basic circuit performing addition operation for binary numbers A and B. This simple combinational circuit obtains two signals S i (sum) and C i+1 (carry to next position) from signals A i, B i and C i (carry from previous position). Fig. 1 presents the truth table and logic symbol of 1-bit adder. A i + B i C i+1 Σ 1 C i S i C i A i B i C i+1 S i 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 Fig.1. 1-bit adder logic symbol and truth table There are also more complex circuits. For example in fig. 2 there is presented n-bit adder. Input signals A and B are represented as signals A n-1...a 0 and B n-1..b 0. Also the output sum is represented as signals S n-1..s 0. This circuit also has carry signals: input (C 0 ) and output (C n ). A n-1...a i...a 1 A 0 + B n-1...b i...b 1 B 0 C Σ C 0 n n S n-1... S i...s 1 S 0 Fig.2. n-bit full adder logic symbol Page 4 of 8

2.2. Binary comparators Another type of logic circuit used with binary numbers is a comparator. Fig. 3 presents the logic symbol and the truth table of 1-bit comparator. A<B A=B A>B A i B i comparator < = > < = > A i B i A< B A= B A> B 0 0 1 0 0 0 0 1 0 0 1 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 1 1 1 0 0 1 0 1 0 0 0 0 1 0 0 1 0 0 1 1 0 0 0 1 0 1 0 0 0 1 0 1 0 1 1 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0 1 1 0 0 1 0 0 1 0 0 0 1 1 0 0 1 1 1 0 0 Fig.3. 1-bit comparator logical symbol and truth table This circuit sets exactly one of outputs A<B, A=B and A>B into state 1 according to compared digits A i and B i and input signals <, = and >. Like adders, also comparators can be realised as n-bit circuit. 2.3. Other circuits Circuits presented above are most commonly used. There are, however, other circuits. One of them is binary subtractor. Presented in fig. 4. 1-bit subtractor realises operation A i -B i -C i where C i signal is called borrow-out bit (borrow from current position to previous). Page 5 of 8

A i - B i C i+1 Σ 1 C i S i Fig.4. 1-bit subtractor logic symbol There are also specialised circuits called arithmetic-logic unit that realise many different operations. One of them is TTL circuit 74181. This circuit realises e.g. addition, subtraction, logical multiplication. The type of operation depends on signals on function inputs F 3..F 0 and M. 2.4. Addition using 2's complement representation To add two numbers written in 2's complement representation we should perform binary addition. If carry from sign digit is detected, it should be ignored. Example: Let (A) 2 =(010011.011) 2 and (B) 2 =(001001.101) 2 then (-A) 2 =(101100.101) 2 and (-B) 2 =(110110.011) 2 +B 001001.101 A+B 011101.000 Number is positive +(-B) 110110.011 A+(-B) 001001.110 Number is positive. Carry is ignored (-A) 101100.101 +B 001001.101 (-A)+B 110110.010 Number is negative. (-A) 101100.101 + (-B) 110110.011 (-A)+(-B) 100011.000 Number is negative. Carry is ignored Note: Result is also in 1's complement representation (except when overflow occurred). Page 6 of 8

2.5. Addition using 1's complement representation To add two numbers written in 1's complement representation we should also perform binary addition. If carry from sign digit is detected, it should be added on the least significant position of the result. Example: Let (A) 2 =(010011.011) 2 and (B) 2 =(001001.101) 2 then (-A) 2 =(101100.100) 2 and (-B) 2 =(110110.010) 2 +B 001001.101 A+B 011101.000 Number is positive +(-B) 110110.010 001001.101 A+(-B) 001001.110 Number is positive. Carry is added (-A) 101100.100 +B 001001.101 (-A)+B 110110.001 Number is negative. (-A) 101100.100 +(-B) 110110.010 100010.110 (-A)+(-B) 100010.111 Number is negative. Carry is added Note: Result is also in 1's complement representation (except when overflow occurred). 2.6. Addition using sign magnitude representation In the case of sign magnitude representation addition is a little complicated. The addition algorithm contains several steps: 1. Check signs of both numbers. 2. If signs are equal (both are positive or negative) add magnitudes and use the sign as sign of the result. 3. If numbers have different signs, convert one (negative) of them to 1's or 2's complement representation, add both numbers using hints from sections 2.4 or 2.5 and if result is negative, convert it into sing magnitude representation. 2.7. Overflow detection Overflow is the most important problem that can occur during addition. Example (2's complement representation): Let (A) 2 =(010011.011) 2 then (-A) 2 =(101100.101) 2 + A+A 100100.110 Error: Result is negative! (-A) 101100.101 +(-A) 101100.101 (-A)+(-A) 011001.010 Error: Result is positive! Page 7 of 8

One of the possible solutions of detecting overflow is based on testing the carry onto and from sign digit. If both carry signals are the same, the result of addition is correct. Otherwise there was overflow error during addition operation (see examples presented above). If overflow occurred, the number of integer digits should be increased (if it is possible). 2.8. Comparison If we use binary comparator for numbers in sign magnitude, 1's or 2's complement representation, the result isn't correct. It is caused by sign bit, which is equal 1 for negative numbers but in binary numbers has the biggest weight. To obtain correct result the negative numbers should be complemented (in 1's and 2's complement representation), or both numbers should be tested like during addition (in sign magnitude representation). Using sign magnitude or 1's complement representation, there is one more problem: there are two zeros: positive (e.g. 0000.0000) and negative (1000.0000 for sign magnitude or 1111.1111 for 1's complement). For these reasons comparator should use an additional combinational circuit, detecting positive and negative zeros and forcing equality one the output. 3. Tasks to be performed during laboratory 1. Obtain full 1-bit adder using NAND gates. 2. Obtain full 1-bit subtractor using NAND gates. 3. Obtain full 1-bit comparator using NAND gates. 4. Obtain full 5-bit adder using one 4-bit adder and NAND gates for numbers in: a) 1 s complement representation b) 2 s complement representation 5. Obtain full 5-bit comparator using one 4-bit comparator and NAND gates for numbers in: a) 1 s complement representation (positive and negative zeros are equal) b) 2 s complement representation 4. Instructions to follow 1. Solve all tasks before the exercise. 2. Implement the circuits specified by your supervisor (using given elements). 3. Present working circuits to your supervisor for acceptance. Page 8 of 8