08 ARTH Page 1 ECEn/CS 224 Number Representation and Binary Arithmetic.

Slides:



Advertisements
Similar presentations
Comparator.
Advertisements

Lab 10 : Arithmetic Systems : Adder System Layout: Slide #2 Slide #3 Slide #4 Slide #5 Arithmetic Overflow: 2’s Complement Conversions: 8 Bit Adder/Subtractor.
Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
ELEC353 S. al Zahir UBC Sign-Magnitude Representation High order bit is sign: 0 = positive (or zero), 1 = negative Low order bits represent the magnitude:
COE 202: Digital Logic Design Signed Numbers
Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University Arithmetic See: P&H Chapter 3.1-3, C.5-6.
Henry Hexmoor1 Chapter 5 Arithmetic Functions Arithmetic functions –Operate on binary vectors –Use the same subfunction in each bit position Can design.
Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker.
Assembly Language and Computer Architecture Using C++ and Java
Fixed-Point Arithmetics: Part I
ECE C03 Lecture 61 Lecture 6 Arithmetic Logic Circuits Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
Assembly Language and Computer Architecture Using C++ and Java
Lecture 8 Arithmetic Logic Circuits
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
1 COMP541 Arithmetic Circuits Montek Singh Mar 20, 2007.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Arithmetic for Computers
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
Basic Arithmetic (adding and subtracting)
Chapter 4 – Arithmetic Functions and HDLs Logic and Computer Design Fundamentals.
Chapter 6-1 ALU, Adder and Subtractor
CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering.
ECEN 301Discussion #19 – Binary Numbers1 Numbered Moses 1:33,35,37 33 And worlds without number have I created; and I also created them for mine own purpose;
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
Charles Kime & Thomas Kaminski © 2004 Pearson Education, Inc. Terms of Use (Hyperlinks are active in View Show mode) Terms of Use Logic and Computer Design.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
MIPS ALU. Building from the adder to ALU ALU – Arithmetic Logic Unit, does the major calculations in the computer, including – Add – And – Or – Sub –
COMP541 Arithmetic Circuits
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Monday, January 13 CEC 220 Digital Circuit Design Slide 1 of 14.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Fri, Aug 28 CEC 220 Digital Circuit Design Slide 1 of 14.
1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 23: Aritmatika 18 Desember 2002 Bobby Nazief Johny Moningka
Addition, Subtraction, Logic Operations and ALU Design
IT1004: Data Representation and Organization Negative number representation.
Registers and Binary Arithmetic Prof. Sirer CS 316 Cornell University.
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
Negative Integers Unsigned binary representation can not be used to represent negative numbers. With paper and pencil arithmetic, a number is made negative.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
Number Representation (Part 2) Computer Architecture (Fall 2006)
Lecture #23: Arithmetic Circuits-1 Arithmetic Circuits (Part I) Randy H. Katz University of California, Berkeley Fall 2005.
MIPS ALU. Exercise – Design a selector? I need a circuit that takes two input bits, a and b, and a selector bit s. The function is that if s=0, f=a. if.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
President UniversityErwin SitompulDigital Systems 7/1 Lecture 7 Digital Systems Dr.-Ing. Erwin Sitompul President University
Computer Engineering page 1 Integer arithmetic Depends what you mean by “integer”. Assume at 3-bit string. –Then we define: zero = 000 one = 001 Use zero,
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Addition and Subtraction
Negative Integers Unsigned binary representation can not be used to represent negative numbers. With paper and pencil arithmetic, a number is made negative.
Digital Systems Section 8 Multiplexers. Digital Systems Section 8 Multiplexers.
MIPS ALU.
King Fahd University of Petroleum and Minerals
MIPS ALU.
Data Representation in Computer Systems
Digital Systems Section 12 Binary Adders. Digital Systems Section 12 Binary Adders.
Unit 18: Computational Thinking
Overview Part 1 – Design Procedure Part 2 – Combinational Logic
Instructor: Alexander Stoytchev
COMS 361 Computer Organization
Presentation transcript:

08 ARTH Page 1 ECEn/CS 224 Number Representation and Binary Arithmetic

08 ARTH Page 2 ECEn/CS 224 Unsigned Addition

08 ARTH Page 3 ECEn/CS 224 Binary Addition = = = = 0 and carry 1 to the next column Examples: 0101 (5 10 ) (2 10 ) 0111 (7 10 ) Carries (5 10 ) (3 10 ) 1000 (8 10 )

08 ARTH Page 4 ECEn/CS 224 Binary Addition w/Overflow Add and in binary Carries (45 10 ) (44 10 ) (89 10 ) If the operands are unsigned, you can use the final carry-out as the MSB of the result. Adding 2 k bit numbers  k+1 bit result

08 ARTH Page 5 ECEn/CS 224 More Binary Addition w/Overflow (15 10 ) (1 10 ) 0000 (0 10 ) If you don’t want a 5-bit result, just keep the lower 4 bits. This is insufficient to hold the result (16). It rolls over back to 0.

08 ARTH Page 6 ECEn/CS 224 Signed Numbers

08 ARTH Page 7 ECEn/CS 224 Negative Binary Numbers Several ways of representing negative numbers Most obvious is to add a sign (+ or -) to the binary integer

08 ARTH Page 8 ECEn/CS 224 Sign-Magnitude 0 is + 1 is - Easy to interpret number value

08 ARTH Page 9 ECEn/CS 224 Sign-Magnitude Examples (+3 10 ) (+4 10 ) (+7 10 ) Signs are the same Just add the magnitudes (-3 10 ) (-4 10 ) (-7 10 )

08 ARTH Page 10 ECEn/CS 224 Another Sign-Magnitude Example (+5 10 ) (-3 10 ) Signs are different - determine which is larger magnitude Put larger magnitude number on top Subtract Result has sign of larger magnitude number… (+5 10 ) (-3 10 ) (+2 10 )

08 ARTH Page 11 ECEn/CS 224 Yet Another Sign-Magnitude Example (+2 10 ) (-5 10 ) Signs are different - determine which is larger magnitude Put larger magnitude number on top Subtract Result has sign of larger magnitude number… (-5 10 ) (+2 10 ) (-3 10 )

08 ARTH Page 12 ECEn/CS 224 Sign-Magnitude Addition requires two separate operations –addition –subtraction Several decisions: –Signs same or different? –Which operand is larger? –What is sign of final result? Two zeroes (+0, -0)

08 ARTH Page 13 ECEn/CS 224 Sign-Magnitude Advantages –Easy to understand Disadvantages –Two different 0s –Hard to implement in logic

08 ARTH Page 14 ECEn/CS 224 One’s Complement Positive numbers are the same as sign- magnitude -N is represented as the complement of N + -N = N’

08 ARTH Page 15 ECEn/CS 224 One’s Complement Examples (5 10 ) (20 10 ) (25 10 ) (5 10 ) (-3 10 ) (+2 10 ) + If there is a carry out on the left, it must be wrapped around and added back in on the right

08 ARTH Page 16 ECEn/CS 224 One’s Complement Addition complicated by end around carry No decisions (like SM) Still two zeroes (+0, -0)

08 ARTH Page 17 ECEn/CS 224 One’s Complement Advantages –Easy to generate –N –Only one addition process Disadvantages –End around carry –Two different 0s

08 ARTH Page 18 ECEn/CS 224 Two’s Complement Treat positional digits differently C = -0 x x x x 2 0 = C = -1 x x x x 2 0 = Most significant bit (MSB) given negative weight… Other bits same as in unsigned

08 ARTH Page 19 ECEn/CS 224 Two’s Complement

08 ARTH Page 20 ECEn/CS 224 Sign-Extension in 2’s Complement To make a k-bit number wider –replicate sign bit 110 2C = -1 x x 2 1 = C = -1 x x x 2 1 = C = -1 x x x x 2 1 = -2 10

08 ARTH Page 21 ECEn/CS 224 More Sign-Extension 010 2C = 1 x 2 1 = C = 1 x 2 1 = C = 1 x 2 1 = 2 10 Works for both positive and negative numbers

08 ARTH Page 22 ECEn/CS 224 Negating a 2’s Complement Number Invert all the bits Add = C → = C = invert = C → = C = invert

08 ARTH Page 23 ECEn/CS 224 Two’s Complement Addition (+5 10 ) (+1 10 ) 0110 (+6 10 ) (-5 10 ) (-1 10 ) 1010 (-6 10 ) (+6 10 ) (-1 10 ) 0101 (+5 10 ) Operation is same as for unsigned Same rules, same procedure Interpretation of operands and results are different

08 ARTH Page 24 ECEn/CS 224 Two’s Complement Addition always the same Only 1 zero Representation of choice…

08 ARTH Page 25 ECEn/CS 224 Two’s Complement Overflow All representations can overflow –Focus on 2’s complement here (-5 10 ) (-4 10 ) 0111 (+7 10 ) ?? The correct answer (-9) cannot be represented by 4 bits The correct answer is 10111

08 ARTH Page 26 ECEn/CS 224 Overflow Can you use leftmost carry-out as new MSB? The answer is no, in general (-5 10 ) (-4 10 ) (-9 10 ) Works here… (-8 10 ) (+7 10 ) ( ) ?? Does NOT work here…

08 ARTH Page 27 ECEn/CS 224 Handling Overflow 1.Sign-extend the operands 2.Do the addition (-8 10 ) (+7 10 ) (-1 10 )

08 ARTH Page 28 ECEn/CS 224 When Can Overflow Occur? Adding two positive numbers - yes Adding two negative numbers – yes Adding a positive to a negative – no Adding a negative to a positive - no

08 ARTH Page 29 ECEn/CS 224 General Handling of Overflow Adding two k bit numbers gives k+1 bit result Two options include: 1.Sign extend and keep entire k+1 bit result 2.Throw away new bit generated (keep only k bits) i.Detect overflow and signal an error ii.Ignore the overflow (this is what most computers do) The choice is up to the designer

08 ARTH Page 30 ECEn/CS 224 Detecting Overflow Overflow occurs if: –Adding two positive numbers gives what looks like a negative result –Adding two negative numbers gives what looks like a positive result Overflow will never occur when adding positive to negative There are other ways of detecting overflow vs. what is suggested here…

08 ARTH Page 31 ECEn/CS 224 Arithmetic Circuits

08 ARTH Page 32 ECEn/CS 224 Binary Adder An example of an iterative network Full Adder A0 S0 C0 S1S2 C3... B0 C1 A1B1 Full Adder C2 Full Adder A2B2 Sn-1 Cn Cn-1 Full Adder An-1Bn-1 This type of adder is also called a ripple-carry adder because the carry ripples through from cell to cell

08 ARTH Page 33 ECEn/CS 224 Full Adder Derivation Si Ci+1 Ai Bi Ci Ai Bi Ci Ai Ci Si Ci+1 Ci Full Adder AiBi

08 ARTH Page 34 ECEn/CS 224 Binary Subtracter Full Sub. X1 D1 B1 D2... Y1 B2 X2Y2 Full Sub. B3 Full Sub. Dn-1 Bn Bn-1 Full Sub. Xn-1Yn-1 D (ifference) = X - Y B is the borrow signal Equations generated similarly to full adder B0 D0 X0Y0

08 ARTH Page 35 ECEn/CS 224 Another Way to Make a Subtracter (2’s complement) Full Adder Full Adder Full Adder Full Adder C 0 = 1 A0A0 B0B0 B1B1 A1A1 B2B2 A2A2 B3B3 A3A3 B0’B0’B1’B1’B2’B2’B3’B3’ S3S3 C4C4 S2S2 C3C3 S1S1 C2C2 S0S0 S = A + (-B) -B is generated by inverting and adding 1 adding 1 C1C1 inverting

08 ARTH Page 36 ECEn/CS 224 Binary Arithmetic Comparison

08 ARTH Page 37 ECEn/CS 224 Summary Understand the three main representation of binary integers –Sign-Magnitude –One’s Complement –Two’s Complement Design binary adders and subtracters for each representation