CprE 281: Digital Logic

Similar documents
CprE 281: Digital Logic

CprE 281: Digital Logic

CprE 281: Digital Logic

CprE 281: Digital Logic

CprE 281: Digital Logic

CprE 281: Digital Logic

CprE 281: Digital Logic

CprE 281: Digital Logic

CprE 281: Digital Logic

UNSIGNED BINARY NUMBERS DIGITAL ELECTRONICS SYSTEM DESIGN WHAT ABOUT NEGATIVE NUMBERS? BINARY ADDITION 11/9/2018

CprE 281: Digital Logic

Combinational Logic Design Arithmetic Functions and Circuits

Total Time = 90 Minutes, Total Marks = 100. Total /10 /25 /20 /10 /15 /20

Module 2. Basic Digital Building Blocks. Binary Arithmetic & Arithmetic Circuits Comparators, Decoders, Encoders, Multiplexors Flip-Flops

We are here. Assembly Language. Processors Arithmetic Logic Units. Finite State Machines. Circuits Gates. Transistors

Combinational Logic. By : Ali Mustafa

Numbers and Arithmetic

Total Time = 90 Minutes, Total Marks = 50. Total /50 /10 /18

E40M. Binary Numbers. M. Horowitz, J. Plummer, R. Howe 1

CprE 281: Digital Logic

Chapter 5 Arithmetic Circuits

Numbers and Arithmetic

Numbers & Arithmetic. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See: P&H Chapter , 3.2, C.5 C.

Logic and Computer Design Fundamentals. Chapter 5 Arithmetic Functions and Circuits

Hakim Weatherspoon CS 3410 Computer Science Cornell University

Chapter 1 CSCI

CprE 281: Digital Logic

convert a two s complement number back into a recognizable magnitude.

ECE380 Digital Logic. Positional representation

14:332:231 DIGITAL LOGIC DESIGN. 2 s-complement Representation

211: Computer Architecture Summer 2016

Introduction to Digital Logic Missouri S&T University CPE 2210 Subtractors

ENGIN 112 Intro to Electrical and Computer Engineering

14:332:231 DIGITAL LOGIC DESIGN. Why Binary Number System?

Carry Look Ahead Adders

CprE 281: Digital Logic

Chapter 03: Computer Arithmetic. Lesson 03: Arithmetic Operations Adder and Subtractor circuits Design

Design of Sequential Circuits

ECE 545 Digital System Design with VHDL Lecture 1. Digital Logic Refresher Part A Combinational Logic Building Blocks

ELCT201: DIGITAL LOGIC DESIGN

Binary addition by hand. Adding two bits

COMBINATIONAL LOGIC FUNCTIONS

XI STANDARD [ COMPUTER SCIENCE ] 5 MARKS STUDY MATERIAL.

CSE 241 Digital Systems Spring 2013

CSCI 255. S i g n e d N u m s / S h i f t i n g / A r i t h m e t i c O p s.

ELEN Electronique numérique

Design of Digital Circuits Reading: Binary Numbers. Required Reading for Week February 2017 Spring 2017

CSE 20 DISCRETE MATH. Fall

Logic. Combinational. inputs. outputs. the result. system can

Binary addition example worked out

What s the Deal? MULTIPLICATION. Time to multiply

Floating Point Representation and Digital Logic. Lecture 11 CS301

Q: Examine the relationship between X and the Next state. How would you describe this circuit? A: An inverter which is synched with a clock signal.

hexadecimal-to-decimal conversion

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

Schedule. ECEN 301 Discussion #25 Final Review 1. Date Day Class No. 1 Dec Mon 25 Final Review. Title Chapters HW Due date. Lab Due date.

CMSC 313 Lecture 17. Focus Groups. Announcement: in-class lab Thu 10/30 Homework 3 Questions Circuits for Addition Midterm Exam returned

XOR - XNOR Gates. The graphic symbol and truth table of XOR gate is shown in the figure.

CMP 334: Seventh Class

Introduction to Digital Logic

UNIT 4 MINTERM AND MAXTERM EXPANSIONS

ECE 250 / CPS 250 Computer Architecture. Basics of Logic Design Boolean Algebra, Logic Gates

Chapter 7 Logic Circuits

Ex code

Numbering Systems. Contents: Binary & Decimal. Converting From: B D, D B. Arithmetic operation on Binary.

Lecture 2 Review on Digital Logic (Part 1)

CHAPTER 2 NUMBER SYSTEMS

14:332:231 DIGITAL LOGIC DESIGN

Fundamentals of Digital Design

Chapter 5. Digital systems. 5.1 Boolean algebra Negation, conjunction and disjunction

Menu. Review of Number Systems EEL3701 EEL3701. Math. Review of number systems >Binary math >Signed number systems

Digital Systems Overview. Unit 1 Numbering Systems. Why Digital Systems? Levels of Design Abstraction. Dissecting Decimal Numbers

Class Website:

Exam for Physics 4051, October 31, 2008

THE LOGIC OF COMPOUND STATEMENTS

CSE 20 Discrete Math. Algebraic Rules for Propositional Formulas. Summer, July 11 (Day 2) Number Systems/Computer Arithmetic Predicate Logic

Computer organization

ECE/CS 250 Computer Architecture

3. Complete the following table of equivalent values. Use binary numbers with a sign bit and 7 bits for the value

Binary addition (1-bit) P Q Y = P + Q Comments Carry = Carry = Carry = Carry = 1 P Q

EE260: Digital Design, Spring n Digital Computers. n Number Systems. n Representations. n Conversions. n Arithmetic Operations.

Addition and Subtraction

Midterm Exam Two is scheduled on April 8 in class. On March 27 I will help you prepare Midterm Exam Two.

EGC221: Digital Logic Lab

CHAPTER 7. Solutions for Exercises

Digital Logic. CS211 Computer Architecture. l Topics. l Transistors (Design & Types) l Logic Gates. l Combinational Circuits.

Systems I: Computer Organization and Architecture

Representing signed numbers in Two s Complement notation

Number representation

Physics 310 Lecture 10 Microprocessors

ECE 545 Digital System Design with VHDL Lecture 1A. Digital Logic Refresher Part A Combinational Logic Building Blocks

Adders - Subtractors

PAST EXAM PAPER & MEMO N3 ABOUT THE QUESTION PAPERS:

Cs302 Quiz for MID TERM Exam Solved

Boolean Algebra & Digital Logic

Digital Logic: Boolean Algebra and Gates. Textbook Chapter 3

CPE100: Digital Logic Design I

CS1800: Hex & Logic. Professor Kevin Gold

CS61C : Machine Structures

Transcription:

CprE 281: Digital Logic Instructor: Alexander Stoytchev http://www.ece.iastate.edu/~alexs/classes/

Signed Numbers CprE 281: Digital Logic Iowa State University, Ames, IA Copyright Alexander Stoytchev

Administrative Stuff HW5 is out It is due on Monday Oct 5 @ 4pm. Please write clearly on the first page (in block capital letters) the following three things: Your First and Last Name Your Student ID Number Your Lab Section Letter

Labs Next Week Administrative Stuff Mini-Project This one is worth 3% of your grade. Make sure to get all the points. http://www.ece.iastate.edu/~alexs/classes/ 2015_Fall_281/labs/Project-Mini/

Quick Review

Adding two bits (there are four possible cases) [ Figure 3.1a from the textbook ]

Adding two bits (the truth table) [ Figure 3.1b from the textbook ]

Adding two bits (the logic circuit) [ Figure 3.1c from the textbook ]

The Half-Adder [ Figure 3.1c-d from the textbook ]

Addition of multibit numbers Bit position i [ Figure 3.2 from the textbook ]

Analogy with addition in base 10 + c 3 c 2 c 1 c 0! x 2 x 1 x 0! y 2 y 1 y 0! s 2 s 1 s 0!!

Analogy with addition in base 10! + 3 8 9! 1 5 7! 5 4 6!

Analogy with addition in base 10 carry 0 1 1 0! + 3 8 9! 1 5 7! 5 4 6!

Analogy with addition in base 10 + c 3 c 2 c 1 c 0! x 2 x 1 x 0! y 2 y 1 y 0! s 2 s 1 s 0!!

Problem Statement and Truth Table [ Figure 3.2b from the textbook ] [ Figure 3.3a from the textbook ]

Let s fill-in the two K-maps [ Figure 3.3a-b from the textbook ]

Let s fill-in the two K-maps [ Figure 3.3a-b from the textbook ]

The circuit for the two expressions [ Figure 3.3c from the textbook ]

This is called the Full-Adder [ Figure 3.3c from the textbook ]

XOR Magic (s i can be implemented in two different ways)

A decomposed implementation of the full-adder circuit c s i s i s HA c x i HA y c c i + 1 i (a) Block diagram c i s i x i y i c i + 1 (b) Detailed diagram [ Figure 3.4 from the textbook ]

The Full-Adder Abstraction c s i s i s HA c x i HA c y c i + 1 i

The Full-Adder Abstraction c i x i FA c i + 1 y i s i

We can place the arrows anywhere x i y i c i+1 FA c i s i

n-bit ripple-carry adder x n 1 y n 1 x 1 y 1 x 0 y 0 c n FA c n 1 c 2 FA c 1 FA c 0 s n 1 s 1 s 0 MSB position LSB position [ Figure 3.5 from the textbook ]

n-bit ripple-carry adder abstraction x n 1 y n 1 x 1 y 1 x 0 y 0 c n FA c n 1 c 2 FA c 1 FA c 0 s n 1 s 1 s 0 MSB position LSB position

n-bit ripple-carry adder abstraction x n 1 y n 1 x 1 y 1 x 0 y 0 c n c 0 s n 1 s 1 s 0

The x and y lines are typically grouped together for better visualization, but the underlying logic remains the same x n 1 x 1 x 0 y 1 y n 1 y 0 c n c 0 s n 1 s 1 s 0

Math Review: Subtraction 39-15??

Math Review: Subtraction 39-15 24

Math Review: Subtraction 82-61 48-26 32-11??????

Math Review: Subtraction 82-61 48-26 32-11 21 22 21

Math Review: Subtraction 82-64 48-29 32-13??????

Math Review: Subtraction 82-64 48-29 32-13 18 19 19

The problems in which row are easier to calculate? 82-61 48-26 32-11?????? 82-64 48-29 32-13??????

The problems in which row are easier to calculate? 82-61 48-26 32-11 Why? 21 22 21 82-64 48-29 32-13 18 19 19

Another Way to Do Subtraction 82 64 = 82 + 100 100-64

Another Way to Do Subtraction 82 64 = 82 + 100 100-64 = 82 + (100 64) - 100

Another Way to Do Subtraction 82 64 = 82 + 100 100-64 = 82 + (100 64) - 100 = 82 + (99 + 1 64) - 100

Another Way to Do Subtraction 82 64 = 82 + 100 100-64 = 82 + (100 64) - 100 = 82 + (99 + 1 64) - 100 = 82 + (99 64) +1-100

Another Way to Do Subtraction 82 64 = 82 + 100 100-64 = 82 + (100 64) - 100 = 82 + (99 + 1 64) - 100 Does not require borrows = 82 + (99 64) +1-100

9 s Complement (subtract each digit from 9) 99-64 35

10 s Complement (subtract each digit from 9 and add 1 to the result) 99-64 35 + 1 = 36

Another Way to Do Subtraction 82 64 = 82 + (99 64) +1-100

Another Way to Do Subtraction 9 s complement 82 64 = 82 + (99 64) +1-100

Another Way to Do Subtraction 9 s complement 82 64 = 82 + (99 64) +1-100 = 82 + 35 + 1-100

Another Way to Do Subtraction 9 s complement 82 64 = 82 + (99 64) +1-100 = 82 + 35 + 1-100 10 s complement

Another Way to Do Subtraction 9 s complement 82 64 = 82 + (99 64) +1-100 = 82 + 35 + 1-100 10 s complement = 82 + 36-100 // add the first two

Another Way to Do Subtraction 9 s complement 82 64 = 82 + (99 64) +1-100 = 82 + 35 + 1-100 10 s complement = 82 + 36-100 = 118-100 // add the first two // delete the leading 1 = 18

Formats for representation of integers b n 1 b 1 b 0 MSB Magnitude (a) Unsigned number b n 1 b n 2 b 1 b 0 Sign 0 denotes + 1 denotes MSB Magnitude (b) Signed number [ Figure 3.7 from the textbook ]

Negative numbers can be represented in following ways Sign and magnitude 1 s complement 2 s complement

1 s complement Let K be the negative equivalent of an n-bit positive number P. Then, in 1 s complement representation K is obtained by subtracting P from 2 n 1, namely K = (2 n 1) P This means that K can be obtained by inverting all bits of P.

Find the 1 s complement of 0 1 0 1 0 0 1 0 0 0 1 1 0 1 1 1

Find the 1 s complement of 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 1 1 1 1 0 0 0 1 1 1 1 0 0 0 Just flip 1's to 0's and vice versa.

A) Example of 1 s complement addition ( + 5 ) + ( + 2 ) ( + 7 ) 0 1 0 1 + 0 0 1 0 0 1 1 1 [ Figure 3.8 from the textbook ]

A) Example of 1 s complement addition ( + 5 ) + ( + 2 ) ( + 7 ) 0 1 0 1 + 0 0 1 0 0 1 1 1

B) Example of 1 s complement addition (- 5 ) + ( + 2 ) (- 3 ) 1 0 1 0 + 0 0 1 0 1 1 0 0 [ Figure 3.8 from the textbook ]

B) Example of 1 s complement addition (- 5 ) + ( + 2 ) (- 3 ) 1 0 1 0 + 0 0 1 0 1 1 0 0

C) Example of 1 s complement addition ( + 5 ) + ( 2 ) ( + 3 ) 0 1 0 1 + 1 1 0 1 1 0 0 1 0 [ Figure 3.8 from the textbook ]

C) Example of 1 s complement addition ( + 5 ) + ( 2 ) ( + 3 ) 0 1 0 1 + 1 1 0 1 1 0 0 1 0

C) Example of 1 s complement addition ( + 5 ) + ( 2 ) ( + 3 ) 0 1 0 1 + 1 1 0 1 1 0 0 1 0 But this is 2!

C) Example of 1 s complement addition ( + 5 ) + ( 2 ) ( + 3 ) 0 1 0 1 + 1 1 0 1 1 0 0 1 0 1 0 0 1 1 We need to perform one more addition to get the result.

C) Example of 1 s complement addition ( + 5 ) + ( 2 ) ( + 3 ) + 0 1 1 1 0 0 1 1 1 0 0 1 0 1 0 0 1 1 We need to perform one more addition to get the result.

D) Example of 1 s complement addition ( 5 ) + ( 2 ) ( 7 ) 1 0 1 0 + 1 1 0 1 1 0 1 1 1 [ Figure 3.8 from the textbook ]

D) Example of 1 s complement addition ( 5 ) + ( 2 ) ( 7 ) 1 0 1 0 + 1 1 0 1 1 0 1 1 1

D) Example of 1 s complement addition ( 5 ) + ( 2 ) ( 7 ) 1 0 1 0 + 1 1 0 1 1 0 1 1 1 But this is +7!

D) Example of 1 s complement addition ( 5 ) + ( 2 ) ( 7 ) 1 0 1 0 + 1 1 0 1 1 0 1 1 1 1 1 0 0 0 We need to perform one more addition to get the result.

D) Example of 1 s complement addition ( 5 ) + ( 2 ) ( 7 ) 1 0 1 0 + 1 1 0 1 1 0 1 1 1 1 1 0 0 0 We need to perform one more addition to get the result.

2 s complement Let K be the negative equivalent of an n-bit positive number P. Then, in 2 s complement representation K is obtained by subtracting P from 2 n, namely K = 2 n P

Deriving 2 s complement For a positive n-bit number P, let K 1 and K 2 denote its 1 s and 2 s complements, respectively. K 1 = (2 n 1) P K 2 = 2 n P Since K 2 = K 1 + 1, it is evident that in a logic circuit the 2 s complement can computed by inverting all bits of P and then adding 1 to the resulting 1 s-complement number.

Find the 2 s complement of 0 1 0 1 0 0 1 0 0 0 1 1 0 1 1 1

Find the 2 s complement of 0 1 0 1 0 0 1 0 1 0 1 1 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1 1 1 0 0 1

Quick Way to find 2 s complement Scan the binary number from right to left Copy all bits that are 0 from right to left Stop at the first 1 Copy that 1 as well Invert all remaining bits

Interpretation of four-bit signed integers [ Table 3.2 from the textbook ]

A) Example of 2 s complement addition ( + 5 ) + ( + 2 ) ( + 7 ) + 0 1 0 1 0 0 1 0 0 1 1 1 [ Figure 3.9 from the textbook ]

B) Example of 2 s complement addition + ( 5 ) ( + 2 ) + 1 0 1 1 0 0 1 0 ( 3 ) 1 1 0 1 [ Figure 3.9 from the textbook ]

C) Example of 2 s complement addition ( + 5 ) + ( 2 ) ( + 3 ) + 1 0 1 0 1 1 1 1 0 0 0 1 1 ignore [ Figure 3.9 from the textbook ]

D) Example of 2 s complement addition ( 5 ) + ( 2 ) ( 7 ) + 1 1 0 1 1 1 1 1 0 1 0 0 1 ignore [ Figure 3.9 from the textbook ]

Example of 2 s complement subtraction ( + 5 ) ( + 2 ) ( + 3 ) 0 1 0 1 0 0 1 0 + 0 1 0 1 1 1 1 0 1 0 0 1 1 ignore [ Figure 3.10 from the textbook ]

Example of 2 s complement subtraction ( 5 ) ( + 2 ) ( 7 ) 1 0 1 1 0 0 1 0 + 1 0 1 1 1 1 1 0 1 1 0 0 1 ignore [ Figure 3.10 from the textbook ]

Example of 2 s complement subtraction ( + 5 ) 0 1 0 1 ( 2 ) 1 1 1 0 + ( + 7 ) 0 1 0 1 0 0 1 0 0 1 1 1 [ Figure 3.10 from the textbook ]

Example of 2 s complement subtraction ( 5 ) 1 0 1 1 ( 2 ) 1 1 1 0 + ( 3 ) 1 0 1 1 0 0 1 0 1 1 0 1 [ Figure 3.10 from the textbook ]

Graphical interpretation of four-bit 2 s complement numbers [ Figure 3.11 from the textbook ]

Take-Home Message Subtraction can be performed by simply adding the 2 s complement of the second number, regardless of the signs of the two numbers. Thus, the same adder circuit can be used to perform both addition and subtraction!!!

Adder/subtractor unit y n 1 y 1 y 0 Add Sub control x n 1 x 1 x 0 c n n -bit adder c 0 s n 1 s 1 s 0 [ Figure 3.12 from the textbook ]

XOR Tricks control out y

XOR as a repeater 0 y y

XOR as an inverter 1 y y

Addition: when control = 0 y n 1 y 1 y 0 Add Sub control x n 1 x 1 x 0 c n n -bit adder c 0 s n 1 s 1 s 0 [ Figure 3.12 from the textbook ]

Addition: when control = 0 y n 1 0 y 1 0 y 0 0 0 Add Sub control x n 1 x 1 x 0 c n n -bit adder c 0 s n 1 s 1 s 0 [ Figure 3.12 from the textbook ]

Addition: when control = 0 y n 1 0 y 1 0 y 0 0 0 Add Sub control x n 1 x 1 x 0 c n n -bit adder y n-1 y 1 y 0 c 0 s n 1 s 1 s 0 [ Figure 3.12 from the textbook ]

Subtraction: when control = 1 y n 1 y 1 y 0 Add Sub control x n 1 x 1 x 0 c n n -bit adder c 0 s n 1 s 1 s 0 [ Figure 3.12 from the textbook ]

Subtraction: when control = 1 y n 1 1 y 1 1 y 0 1 1 Add Sub control x n 1 x 1 x 0 c n n -bit adder c 0 s n 1 s 1 s 0 [ Figure 3.12 from the textbook ]

Subtraction: when control = 1 y n 1 1 y 1 1 y 0 1 1 Add Sub control x n 1 x 1 x 0 c n n -bit adder y n-1 y 1 y 0 c 0 s n 1 s 1 s 0 [ Figure 3.12 from the textbook ]

Subtraction: when control = 1 y n 1 1 y 1 1 y 0 1 1 Add Sub control x n 1 x 1 x 0 c n n -bit adder y n-1 y 1 y 0 1 c 0 s n 1 s 1 s 0 carry for the first column! [ Figure 3.12 from the textbook ]

Examples of determination of overflow + ( + 7 ) ( + 2 ) + 0 1 1 1 0 0 1 0 + ( 7 ) ( + 2 ) + 1 0 0 1 0 0 1 0 ( + 9 ) 1 0 0 1 c 4 = 0 c 3 = 1 ( 5 ) 1 0 1 1 c 4 = 0 c 3 = 0 ( + 7 ) + ( 2 ) + 0 1 1 1 1 1 1 0 ( 7 ) + ( 2 ) + 1 0 0 1 1 1 1 0 ( + 5 ) 1 0 1 0 1 c 4 = 1 c 3 = 1 ( 9 ) 1 0 1 1 1 c 4 = 1 c 3 = 0 [ Figure 3.13 from the textbook ]

Examples of determination of overflow + ( + 7 ) ( + 2 ) + 0 1 1 1 0 0 1 0 + ( 7 ) ( + 2 ) + 1 0 0 1 0 0 1 0 ( + 9 ) ( + 7 ) + ( 2 ) 1 0 0 1 c 4 = 0 c 3 = 1 + 0 1 1 1 1 1 1 0 ( 5 ) Overflow occurs only in these two cases. ( 7 ) + ( 2 ) + 1 0 1 1 c 4 = 0 c 3 = 0 1 0 0 1 1 1 1 0 ( + 5 ) 1 0 1 0 1 c 4 = 1 c 3 = 1 ( 9 ) 1 0 1 1 1 c 4 = 1 c 3 = 0 [ Figure 3.13 from the textbook ]

Examples of determination of overflow + ( + 7 ) ( + 2 ) + 0 1 1 1 0 0 1 0 + ( 7 ) ( + 2 ) + 1 0 0 1 0 0 1 0 ( + 9 ) ( + 7 ) + ( 2 ) 1 0 0 1 c 4 = 0 c 3 = 1 + 0 1 1 1 1 1 1 0 ( 5 ) Overflow occurs only in these two cases. ( 7 ) + ( 2 ) + 1 0 1 1 c 4 = 0 c 3 = 0 1 0 0 1 1 1 1 0 ( + 5 ) 1 0 1 0 1 c 4 = 1 c 3 = 1 ( 9 ) 1 0 1 1 1 c 4 = 1 c 3 = 0 Overflow = c 3 c 4 + c 3 c 4 [ Figure 3.13 from the textbook ]

Examples of determination of overflow + ( + 7 ) ( + 2 ) + 0 1 1 1 0 0 1 0 + ( 7 ) ( + 2 ) + 1 0 0 1 0 0 1 0 ( + 9 ) ( + 7 ) + ( 2 ) 1 0 0 1 c 4 = 0 c 3 = 1 + 0 1 1 1 1 1 1 0 ( 5 ) Overflow occurs only in these two cases. ( 7 ) + ( 2 ) + 1 0 1 1 c 4 = 0 c 3 = 0 1 0 0 1 1 1 1 0 ( + 5 ) 1 0 1 0 1 c 4 = 1 c 3 = 1 ( 9 ) 1 0 1 1 1 c 4 = 1 c 3 = 0 Overflow = c 3 c 4 + c 3 c 4 XOR [ Figure 3.13 from the textbook ]

Calculating overflow for 4-bit numbers with only three significant bits

Calculating overflow for n-bit numbers with only n-1 significant bits

Another way to look at the overflow issue

Another way to look at the overflow issue If both numbers that we are adding have the same sign but the sum does not, then we have an overflow.

Questions?

THE END