June 19, 2002Addition and multiplication1 Delays in the ripple carry adder The diagram below shows a 4-bit adder completely drawn out. This is called a.

Slides:



Advertisements
Similar presentations
EET 1131 Unit 7 Arithmetic Operations and Circuits
Advertisements

Arithmetic Functions and Circuits
Arithmetic Operations and Circuits
Henry Hexmoor1 Chapter 5 Arithmetic Functions Arithmetic functions –Operate on binary vectors –Use the same subfunction in each bit position Can design.
Wakerly Section 2.4 and further Addition and Subtraction of Nondecimal Numbers.
Assembly Language and Computer Architecture Using C++ and Java
Chapter 4 Operations on Bits
Chapter 6 Arithmetic. Addition Carry in Carry out
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
Chapter # 5: Arithmetic Circuits Contemporary Logic Design Randy H
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.
ECE 301 – Digital Electronics
Copyright 2008 Koren ECE666/Koren Part.6a.1 Israel Koren Spring 2008 UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering Digital Computer.
1  1998 Morgan Kaufmann Publishers Chapter Four Arithmetic for Computers.
Chapter 5 Arithmetic Logic Functions. Page 2 This Chapter..  We will be looking at multi-valued arithmetic and logic functions  Bitwise AND, OR, EXOR,
Lecture # 12 University of Tehran
Arithmetic-logic units
Building Adders & Sub tractors Dr Ahmed Telba. Introducing adder circuits Adder circuits are essential inside microprocessors as part of the ALU, or arithmetic.
Operations on data CHAPTER 4.
4 Operations On Data Foundations of Computer Science ã Cengage Learning.
3-1 Chapter 3 - Arithmetic Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer Architecture.
Dr. Bernard Chen Ph.D. University of Central Arkansas
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.
Data Representation – Binary Numbers
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
Computer Arithmetic Nizamettin AYDIN
Binary Arithmetic Stephen Boyd March 14, Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave.
3-1 Chapter 3 - Arithmetic Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles of Computer Architecture.
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
Basic Arithmetic (adding and subtracting)
IT253: Computer Organization
IKI a-Combinatorial Components Bobby Nazief Semester-I The materials on these slides are adopted from those in CS231’s Lecture Notes.
Chapter 4 – Arithmetic Functions and HDLs Logic and Computer Design Fundamentals.
Chapter # 5: Arithmetic Circuits
Chapter 6-1 ALU, Adder and Subtractor
5-1 Programmable and Steering Logic Chapter # 5: Arithmetic Circuits.
07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić.
IKI Data Types & Representations Bobby Nazief Semester-I The materials on these slides are adopted from those in CS231’s Lecture Notes.
Operations on Bits Arithmetic Operations Logic Operations
درس مدارهای منطقی دانشگاه قم مدارهای منطقی محاسباتی تهیه شده توسط حسین امیرخانی مبتنی بر اسلایدهای درس مدارهای منطقی دانشگاه.
COMP541 Arithmetic Circuits
Combinational Circuits
Sep 29, 2004Subtraction (lvk)1 Negative Numbers and Subtraction The adders we designed can add only non-negative numbers – If we can represent negative.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
Topics covered: Arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
COMP541 Arithmetic Circuits
69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position.
Addition and multiplication Arithmetic is the most basic thing you can do with a computer, but it’s not as easy as you might expect! These next few lectures.
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.
ECE DIGITAL LOGIC LECTURE 15: COMBINATIONAL CIRCUITS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2015, 10/20/2015.
President UniversityErwin SitompulDigital Systems 7/1 Lecture 7 Digital Systems Dr.-Ing. Erwin Sitompul President University
ETE 204 – Digital Electronics Combinational Logic Design Single-bit and Multiple-bit Adder Circuits [Lecture: 9] Instructor: Sajib Roy Lecturer, ETE,ULAB.
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
Addition and multiplication1 Arithmetic is the most basic thing you can do with a computer, but it’s not as easy as you might expect! These next few lectures.
Chapter 6. Digital Arithmetic: Operations and Circuits
Representing Positive and Negative Numbers
Negative Numbers and Subtraction
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
Addition and multiplication
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Digital Logic & Design Lecture 02.
Digital Systems Section 12 Binary Adders. Digital Systems Section 12 Binary Adders.
Addition and multiplication
One’s complement addition
Addition and multiplication
ECE 352 Digital System Fundamentals
Presentation transcript:

June 19, 2002Addition and multiplication1 Delays in the ripple carry adder The diagram below shows a 4-bit adder completely drawn out. This is called a ripple carry adder, because the inputs A 0, B 0 and CI “ripple” leftwards until CO and S 3 are produced. Ripple carry adders are slow! – Our example addition with 4-bit inputs required 5 “steps.” – There is a very long path from A 0, B 0 and CI to CO and S 3. – For an n-bit ripple carry adder, the longest path has 2n+1 gates. – Imagine a 64-bit adder. The longest path would have 129 gates!

June 19, 2002Addition and multiplication2 Algebraic carry out hocus-pocus Let’s look at the carry out equations for specific bits, using the general equation from the previous page c i+1 = g i + p i c i : These expressions are all sums of products, so we can use them to make a circuit with only a two-level delay. c 1 = g 0 + p 0 c 0 c 2 = g 1 + p 1 c 1 = g 1 + p 1 (g 0 + p 0 c 0 ) = g 1 + p 1 g 0 + p 1 p 0 c 0 c 3 = g 2 + p 2 c 2 = g 2 + p 2 (g 1 + p 1 g 0 + p 1 p 0 c 0 ) = g 2 + p 2 g 1 + p 2 p 1 g 0 + p 2 p 1 p 0 c 0 c 4 = g 3 + p 3 c 3 = g 3 + p 3 (g 2 + p 2 g 1 + p 2 p 1 g 0 + p 2 p 1 p 0 c 0 ) = g 3 + p 3 g 2 + p 3 p 2 g 1 + p 3 p 2 p 1 g 0 + p 3 p 2 p 1 p 0 c 0 Ready to see the circuit?

June 19, 2002Addition and multiplication3 A 4-bit carry lookahead adder circuit “carry-out”, not “c-zero” Lookahead ckt

June 19, 2002Addition and multiplication4 Carry lookahead adders This is called a carry lookahead adder. By adding more hardware, we reduced the number of levels in the circuit and sped things up. How can we extend this more than 4 bits? The same techinque of algebraic substitution? – No. because the fan-in and fan-out ( I.e.. number of inputs and outputs to gates) keeps increasing We can “cascade” carry lookahead adders, just like ripple carry adders. (We’d have to do carry lookahead between the adders too.) Second level carry lookahead ckt 4 bit look-ahead adders gpgpgpgp

June 19, 2002Addition and multiplication5 Carry lookahead adders How much faster is this? – For a 4-bit adder, not much. There are 4 gates in the longest path of a carry lookahead adder, versus 9 gates for a ripple carry adder. – But if we do the cascading properly, a 16-bit carry lookahead adder could have only 8 gates in the longest path, as opposed to 33 for a ripple carry adder. – Newer CPUs these days use 64-bit adders. That’s 12 vs. 129 gates! The delay of a carry lookahead adder grows logarithmically with the size of the adder, while a ripple carry adder’s delay grows linearly. The thing to remember about this is the trade-off between complexity and performance. Ripple carry adders are simpler, but slower. Carry lookahead adders are faster but more complex.

June 19, 2002Addition and multiplication6 Addition summary We can use circuits call full-adders to add three bits together to produce a two-bit output. The two outputs are called the sum (which is part of the answer) and the carry (which is just the same as the carry from the addition you learned to do by hand back in third grade.) We can string several full adders together to get adders that work for numbers with more than one bit. By connecting the carry-out of one adder to the carry-in of the next, we get a ripple carry adder. We can get fancy by using two-level circuitry to compute the carry-in for each adder. This is called carry lookahead. Carry lookahead adders can be much faster than ripple carry adders.

June 19, 2002Addition and multiplication7 Multiplication Multiplication can’t be that hard! – It’s just repeated addition. – If we have adders, we can do multiplication also. Remember that the AND operation is equivalent to multiplication on two bits:

June 19, 2002Addition and multiplication8 Binary multiplication example Since we always multiply by either 0 or 1, the partial products are always either 0000 or the multiplicand (1101 in this example). There are four partial products which are added to form the result. – We can add them in pairs, using three adders. – Even though the product has up to 8 bits, we can use 4-bit adders if we “stagger” them leftwards, like the partial products themselves. 1101Multiplicand x0110Multiplier 0000Partial products Product

June 19, 2002Addition and multiplication9 A 2x2 binary multiplier The AND gates produce the partial products. For a 2-bit by 2-bit multiplier, we can just use two half adders to sum the partial products. In general, though, we’ll need full adders. Here C 3 -C 0 are the product, not carries!

June 19, 2002Addition and multiplication10 A 4x4 multiplier circuit

June 19, 2002Addition and multiplication11 More on multipliers Notice that this 4-bit multiplier produces an 8-bit result. – We could just keep all 8 bits. – Or, if we needed a 4-bit result, we could ignore C4-C7, and consider it an overflow condition if the result is longer than 4 bits. Multipliers are very complex circuits. – In general, when multiplying an m-bit number by an n-bit number: There are n partial products, one for each bit of the multiplier. This requires n-1 adders, each of which can add m bits (the size of the multiplicand). – The circuit for 32-bit or 64-bit multiplication would be huge!

June 19, 2002Addition and multiplication12 Multiplication: a special case In decimal, an easy way to multiply by 10 is to shift all the digits to the left, and tack a 0 to the right end. 128 x 10 = 1280 We can do the same thing in binary. Shifting left is equivalent to multiplying by 2: 11 x 10 = 110(in decimal, 3 x 2 = 6) Shifting left twice is equivalent to multiplying by 4: 11 x 100 = 1100(in decimal, 3 x 4 = 12) As an aside, shifting to the right is equivalent to dividing by ÷ 10 = 11(in decimal, 6 ÷ 2 = 3)

June 19, 2002Addition and multiplication13 Addition and multiplication summary Adder and multiplier circuits mimic human algorithms for addition and multiplication. Adders and multipliers are built hierarchically. – We start with half adders or full adders and work our way up. – Building these functions from scratch with truth tables and K-maps would be pretty difficult. The arithmetic circuits impose a limit on the number of bits that can be added. Exceeding this limit results in overflow. There is a tradeoff between simple but slow circuits (ripple carry adders) and complex but fast circuits (carry lookahead adders). Multiplication and division by powers of 2 can be handled with simple shifting.

June 24, 2002© Howard Huang14 Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. – The main problem is representing negative numbers in binary. We introduce three methods, and show why one of them is the best. – With negative numbers, we’ll be able to do subtraction using the adders we made last time, because A - B = A + (-B).

June 19, 2002Addition and multiplication15 Representations and algorithms We’ll look at three different ways of representing signed numbers. How can we decide representation is better? – The best one should result in the simplest and fastest operations. – This is just like choosing a data structure in programming. We’re mostly concerned with two particular operations: – Negating a signed number, or converting x into -x. – Adding two signed numbers, or computing x + y.

June 19, 2002Addition and multiplication16 Signed magnitude representation Humans use a signed-magnitude system: we add + or - in front of a magnitude to indicate the sign. We could do this in binary as well, by adding an extra sign bit to the front of our numbers. By convention: – A 0 sign bit represents a positive number. – A 1 sign bit represents a negative number. Examples: = (a 4-bit unsigned number) 01101= (a positive number in 5-bit signed magnitude) 11101= (a negative number in 5-bit signed magnitude) = 4 10 (a 4-bit unsigned number) 00100= (a positive number in 5-bit signed magnitude) 10100= (a negative number in 5-bit signed magnitude)

June 19, 2002Addition and multiplication17 Signed magnitude operations Negating a signed-magnitude number is trivial: just change the sign bit from 0 to 1, or vice versa. Adding numbers is difficult, though. Signed magnitude is basically what people use, so think about the grade-school approach to addition. It’s based on comparing the signs of the augend and addend: – If they have the same sign, add the magnitudes and keep that sign. – If they have different signs, then subtract the smaller magnitude from the larger one. The sign of the number with the larger magnitude is the sign of the result. This method of subtraction would lead to a rather complex circuit because

June 19, 2002Addition and multiplication18 One’s complement representation A different approach, one’s complement, negates numbers by complementing each bit of the number. We keep the sign bits: 0 for positive numbers, and 1 for negative. The sign bit is complemented along with the rest of the bits. Examples: = (a 4-bit unsigned number) 01101= (a positive number in 5-bit one’s complement) 10010= (a negative number in 5-bit one’s complement) = 4 10 (a 4-bit unsigned number) 00100= (a positive number in 5-bit one’s complement) 11011= (a negative number in 5-bit one’s complement)

June 19, 2002Addition and multiplication19 Why is it called “one’s complement?” Complementing a single bit is equivalent to subtracting it from 1. 0’ = 1, and = 11’ = 0, and = 0 Similarly, complementing each bit of an n-bit number is equivalent to subtracting that number from 2 n -1. For example, we can negate the 5-bit number – Here n=5, and 2 n -1 = = – Subtracting from yields 10010:

June 19, 2002Addition and multiplication20 One’s complement addition To add one’s complement numbers: – First do unsigned addition on the numbers, including the sign bits. – Then take the carry out and add it to the sum. Two examples: This is simpler and more uniform than signed magnitude addition. 0111(+7) (-4) (+3) (+2) (+5)

June 19, 2002Addition and multiplication21 Two’s complement Our final idea is two’s complement. To negate a number, complement each bit (just as for ones’ complement) and then add 1. Examples: = (a 4-bit unsigned number) 01101= (a positive number in 5-bit two’s complement) 10010= (a negative number in 5-bit ones’ complement) 10011= (a negative number in 5-bit two’s complement) = 4 10 (a 4-bit unsigned number) 00100= (a positive number in 5-bit two’s complement) 11011= (a negative number in 5-bit ones’ complement) 11100= (a negative number in 5-bit two’s complement)

June 19, 2002Addition and multiplication22 Two other equivalent ways to negate two’s complement numbers: – You can subtract an n-bit two’s complement number from 2 n. – You can complement all of the bits to the left of the rightmost = (a positive number in two’s complement) 10011= (a negative number in two’s complement) 00100= (a positive number in two’s complement) 11100= (a negative number in two’s complement) Often, people talk about “taking the two’s complement” of a number. This is a confusing phrase, but it usually means to negate some number that’s already in two’s complement format. More about two’s complement ( ) 10011( ) (+4 10 ) 11100(-4 10 )

June 19, 2002Addition and multiplication23 Two’s complement addition Negating a two’s complement number takes a bit of work, but addition is much easier than with the other two systems. To find A + B, you just have to: – Do unsigned addition on A and B, including their sign bits. – Ignore any carry out. For example, to find , or (+7) + (-4): – First add as unsigned numbers: – Discard the carry out (1). – The answer is 0011 (+3)

June 19, 2002Addition and multiplication24 Another two’s complement example To further convince you that this works, let’s try adding two negative numbers— , or (-3) + (-2) in decimal. Adding the numbers gives 11011: Dropping the carry out (1) leaves us with the answer, 1011 (-5)

June 19, 2002Addition and multiplication25 Why does this work? For n-bit numbers, the negation of B in two’s complement is 2 n - B (this is one of the alternative ways of negating a two’s-complement number). A - B= A + (-B) = A + (2 n - B) = (A - B) + 2 n If A  B, then (A - B) is a positive number, and 2 n represents a carry out of 1. Discarding this carry out is equivalent to subtracting 2 n, which leaves us with the desired result (A - B). If A  B, then (A - B) is a negative number and we have 2 n - (A - B). This corresponds to the desired result, -(A - B), in two’s complement form.

June 19, 2002Addition and multiplication26 Comparing the signed number systems Here are all the 4-bit numbers in the different systems. Positive numbers are the same in all three representations. Signed magnitude and one’s complement have two ways of representing 0. This makes things more complicated. Two’s complement has asymmetric ranges; there is one more negative number than positive number. Here, you can represent -8 but not +8. However, two’s complement is preferred because it has only one 0, and its addition algorithm is the simplest.

June 19, 2002Addition and multiplication27 How many negative and positive numbers can be represented in each of the different systems on the previous page? In general, with n-bit numbers including the sign, the ranges are: Ranges of the signed number systems

June 19, 2002Addition and multiplication28 Converting signed numbers to decimal Convert to decimal, assuming this is a number in: (a) signed magnitude format (b) ones’ complement (c) two’s complement

June 19, 2002Addition and multiplication29 Example solution Convert to decimal, assuming this is a number in: Since the sign bit is 1, this is a negative number. The easiest way to find the magnitude is to convert it to a positive number. (a) signed magnitude format Negating the original number, , gives , which is +21 in decimal. So must represent -21. (b) ones’ complement Negating in ones’ complement yields = , so the original number must have been (c) two’s complement Negating in two’s complement gives = 11 10, which means = The most important point here is that a binary number has different meanings depending on which representation is assumed.

June 19, 2002Addition and multiplication30 Our four-bit unsigned adder circuit Here is the four-bit unsigned addition circuit from last Wednesday. Nope, never saw it before in my life.

June 19, 2002Addition and multiplication31 Making a subtraction circuit We could build a subtraction circuit directly, similar to the way we made unsigned adders yesterday. However, by using two’s complement we can convert any subtraction problem into an addition problem. Algebraically, A - B = A + (-B) So to subtract B from A, we can instead add the negation of B to A. This way we can re-use the unsigned adder hardware from last week.

June 19, 2002Addition and multiplication32 A two’s complement subtraction circuit To find A - B with an adder, we’ll need to: – Complement each bit of B. – Set the adder’s carry in to 1. The net result is A + B’ + 1, where B’ + 1 is the two’s complement negation of B. Remember that A3, B3 and S3 here are actually sign bits.

June 19, 2002Addition and multiplication33 Small differences The only differences between the adder and subtractor circuits are: – The subtractor has to negate B3 B2 B1 B0. – The subtractor sets the initial carry in to 1, instead of 0. It’s not too hard to make one circuit that does both addition and subtraction.

June 19, 2002Addition and multiplication34 An adder-subtractor circuit XOR gates let us selectively complement the B input. X  0 = XX  1 = X’ When Sub = 0, the XOR gates output B3 B2 B1 B0 and the carry in is 0. The adder output will be A + B + 0, or just A + B. When Sub = 1, the XOR gates output B3’ B2’ B1’ B0’ and the carry in is 1. Thus, the adder output will be a two’s complement subtraction, A - B.

June 19, 2002Addition and multiplication35 Signed overflow With two’s complement and a 4-bit adder, for example, the largest representable decimal number is +7, and the smallest is -8. What if you try to compute 4 + 5, or (-4) + (-5)? We cannot just include the carry out to produce a five-digit result, as for unsigned addition. If we did, (-4) + (-5) would result in +23! Also, unlike the case with unsigned numbers, the carry out cannot be used to detect overflow. – In the example on the left, the carry out is 0 but there is overflow. – Conversely, there are situations where the carry out is 1 but there is no overflow. 0100(+4) +0101(+5) 01001(-7) 1100(-4) +1011(-5) 10111(+7)

June 19, 2002Addition and multiplication36 Detecting signed overflow The easiest way to detect signed overflow is to look at all the sign bits. Overflow occurs only in the two situations above: – If you add two positive numbers and get a negative result. – If you add two negative numbers and get a positive result. Overflow cannot occur if you add a positive number to a negative number. Do you see why? 0100(+4) +0101(+5) 01001(-7) 1100(-4) +1011(-5) 10111(+7)

June 19, 2002Addition and multiplication37 Sign extension In everyday life, decimal numbers are assumed to have an infinite number of 0s in front of them. This helps in “lining up” numbers. To subtract 231 and 3, for instance, you can imagine: You need to be careful in extending signed binary numbers, because the leftmost bit is the sign and not part of the magnitude. If you just add 0s in front, you might accidentally change a negative number into a positive one! For example, going from 4-bit to 8-bit numbers: – 0101 (+5) should become (+5). – But 1100 (-4) should become (-4). The proper way to extend a signed binary number is to replicate the sign bit, so the sign is preserved.

June 19, 2002Addition and multiplication38 Subtraction summary A good representation for negative numbers makes subtraction hardware much easier to design. – Two’s complement is used most often (although signed magnitude shows up sometimes, such as in floating-point systems, which we’ll discuss on Wednesday). – Using two’s complement, we can build a subtractor with minor changes to the adder from last week. – We can also make a single circuit which can both add and subtract. Overflow is still a problem, but signed overflow is very different from the unsigned overflow we mentioned last time. Sign extension is needed to properly “lengthen” negative numbers. Tomorrow we’ll use most of the ideas we’ve seen so far to build an ALU – an important part of a processor.