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.

Slides:



Advertisements
Similar presentations
Addition and multiplication
Advertisements

L10 – Transistors Logic Math 1 Comp 411 – Spring /22/07 Arithmetic Circuits Didn’t I learn how to do addition in the second grade?
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.
ECE 331 – Digital System Design
CSE-221 Digital Logic Design (DLD)
Computer Structure - The ALU Goal: Build an ALU  The Arithmetic Logic Unit or ALU is the device that performs arithmetic and logical operations in the.
L9 – Arithmetic Circuits 1 Comp 411 – Fall /14/09 Arithmetic Circuits Didn’t I learn how to do addition in the second grade?
ECE C03 Lecture 61 Lecture 6 Arithmetic Logic Circuits Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
Chapter # 5: Arithmetic Circuits Contemporary Logic Design Randy H
Design of Arithmetic Circuits – Adders, Subtractors, BCD adders
ECE 301 – Digital Electronics
ECE 301 – Digital Electronics
ECE 301 – Digital Electronics
Chapter 5 Arithmetic Logic Functions. Page 2 This Chapter..  We will be looking at multi-valued arithmetic and logic functions  Bitwise AND, OR, EXOR,
Building Adders & Sub tractors Dr Ahmed Telba. Introducing adder circuits Adder circuits are essential inside microprocessors as part of the ALU, or arithmetic.
 Arithmetic circuit  Addition  Subtraction  Division  Multiplication.
CS 105 Digital Logic Design
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.
CS231: Computer Architecture I Laxmikant Kale Fall 2004.
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
Chapter 6-2 Multiplier Multiplier Next Lecture Divider
Logical Circuit Design Week 8: Arithmetic Circuits Mentor Hamiti, MSc Office ,
Basic Arithmetic (adding and subtracting)
+ CS 325: CS Hardware and Software Organization and Architecture Combinational Circuits 1.
CS1Q Computer Systems Lecture 9 Simon Gay. Lecture 9CS1Q Computer Systems - Simon Gay2 Addition We want to be able to do arithmetic on computers and therefore.
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
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.
Basic Arithmetic (adding and subtracting)
Logic Gates Logic gates are electronic digital circuit perform logic functions. Commonly expected logic functions are already having the corresponding.
1 Arithmetic Logic Unit ALU. 2 The Bus Concept 3 CPU Building Blocks  Registers (IR, PC, ACC)  Control Unit (CU)  Arithmetic Logic Unit (ALU)
درس مدارهای منطقی دانشگاه قم مدارهای منطقی محاسباتی تهیه شده توسط حسین امیرخانی مبتنی بر اسلایدهای درس مدارهای منطقی دانشگاه.
IT253: Computer Organization Lecture 7: Logic and Gates: Digital Design Tonga Institute of Higher Education.
1 Lecture 6 BOOLEAN ALGEBRA and GATES Building a 32 bit processor PH 3: B.1-B.5.
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.
1 CS 151: Digital Design Chapter 4: Arithmetic Functions and Circuits 4-1,2: Iterative Combinational Circuits and Binary Adders.
EE2174: Digital Logic and Lab Professor Shiyan Hu Department of Electrical and Computer Engineering Michigan Technological University CHAPTER 8 Arithmetic.
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.
Topics covered: Arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
1 KU College of Engineering Elec 204: Digital Systems Design Lecture 10 Multiplexers MUX: –Selects binary information from one of many input lines and.
1 Chapter 4 Combinational Logic Logic circuits for digital systems may be combinational or sequential. A combinational circuit consists of input variables,
CPEN Digital System Design
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.
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
Explain Half Adder and Full Adder with Truth Table.
LOGIC CIRCUITLOGIC CIRCUIT. Goal To understand how digital a computer can work, at the lowest level. To understand what is possible and the limitations.
Logic Design (CE1111 ) Lecture 4 (Chapter 4) Combinational Logic Prepared by Dr. Lamiaa Elshenawy 1.
ETE 204 – Digital Electronics Combinational Logic Design Single-bit and Multiple-bit Adder Circuits [Lecture: 9] Instructor: Sajib Roy Lecturer, ETE,ULAB.
Gunjeet Kaur Dronacharya Group of Institutions. Binary Adder-Subtractor A combinational circuit that performs the addition of two bits is called a half.
Negative Numbers and Subtraction
Addition and multiplication
Binary Addition and Subtraction
Arithmetic Circuits Didn’t I learn how
CSE Winter 2001 – Arithmetic Unit - 1
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Overview Part 1 – Design Procedure Part 2 – Combinational Logic
Arithmetic and Decisions
Addition and multiplication
CS231: Computer Architecture I
Addition and multiplication
ECE 352 Digital System Fundamentals
XOR Function Logic Symbol  Description  Truth Table 
Presentation transcript:

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 focus on addition, subtraction, multiplication and arithmetic-logic units, or ALUs, which are the “heart” of CPUs. ALUs are a good example of many of the issues we’ve seen so far, including Boolean algebra, circuit analysis, data representation, and hierarchical, modular design.

Addition and multiplication2 Binary addition by hand You can add two binary numbers one column at a time starting from the right, just as you add two decimal numbers. But remember that it’s binary. For example, = 10 and you have to carry! 1110Carry in 1011Augend +1110Addend 11001Sum The initial carry in is implicitly 0 most significant bit, or MSB least significant bit, or LSB

Addition and multiplication3 Adding two bits We’ll make a hardware adder by copying the human addition algorithm. We start with a half adder, which adds two bits and produces a two-bit result: a sum (the right bit) and a carry out (the left bit). Here are truth tables, equations, circuit and block symbol. 0+ 0= = = = 10 C= XY S= X’ Y + X Y’ = X  Y Be careful! Now we’re using + for both arithmetic addition and the logical OR operation.

Addition and multiplication4 Adding three bits But what we really need to do is add three bits: the augend and addend, and the carry in from the right = = = = = = = = 11 (These are the same functions from the decoder and mux examples.)

Addition and multiplication5 Full adder equations A full adder circuit takes three bits of input, and produces a two-bit output consisting of a sum and a carry out. Using Boolean algebra, we get the equations shown here. – XOR operations simplify the equations a bit. – We used algebra because you can’t easily derive XORs from K-maps. S=  m(1,2,4,7) = X’ Y’ C in + X’ Y C in ’ + X Y’ C in ’ + X Y C in = X’ (Y’ C in + Y C in ’) + X (Y’ C in ’ + Y C in ) = X’ (Y  C in ) + X (Y  C in )’ = X  Y  C in C out =  m(3,5,6,7) = X’ Y C in + X Y’ C in + X Y C in ’ + X Y C in = (X’ Y + X Y’) C in + XY(C in ’ + C in ) = (X  Y) C in + XY

Addition and multiplication6 Full adder circuit These things are called half adders and full adders because you can build a full adder by putting together two half adders! S= X  Y  C in C out = (X  Y) C in + XY

Addition and multiplication7 A 4-bit adder Four full adders together make a 4-bit adder. There are nine total inputs: – Two 4-bit numbers, A3 A2 A1 A0 and B3 B2 B1 B0 – An initial carry in, CI The five outputs are: – A 4-bit sum, S3 S2 S1 S0 – A carry out, CO Imagine designing a nine-input adder without this hierarchical structure—you’d have a 512-row truth table with five outputs!

Addition and multiplication8 An example of 4-bit addition Let’s try our initial example: A=1011 (eleven), B=1110 (fourteen) Fill in all the inputs, including CI=0 1 5.Use C3 to compute CO and S3 ( = 11) 0 2.The circuit produces C1 and S0 ( = 01) Use C1 to find C2 and S1 ( = 10) Use C2 to compute C3 and S2 ( = 10) 0 Woohoo! The final answer is (twenty-five).

Addition and multiplication9 Overflow In this case, note that the answer (11001) is five bits long, while the inputs were each only four bits (1011 and 1110). This is called overflow. Although the answer is correct, we cannot use that answer in any subsequent computations with this 4-bit adder. For unsigned addition, overflow occurs when the carry out is 1.

Addition and multiplication10 Hierarchical adder design When you add two 4-bit numbers the carry in is always 0, so why does the 4-bit adder have a CI input? One reason is so we can put 4-bit adders together to make even larger adders! This is just like how we put four full adders together to make the 4-bit adder in the first place. Here is an 8-bit adder, for example. CI is also useful for subtraction, as we’ll see next week.

Addition and multiplication11 Gate delays Every gate takes some small fraction of a second between the time inputs are presented and the time the correct answer appears on the outputs. This little fraction of a second is called a gate delay. There are actually detailed ways of calculating gate delays that can get quite complicated, but for this class, let’s just assume that there’s some small constant delay that’s the same for all gates. We can use a timing diagram to show gate delays graphically. x x’ 1 0 gate delays

Addition and multiplication12 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!

Addition and multiplication13 A faster way to compute carry outs Instead of waiting for the carry out from all the previous stages, we could compute it directly with a two-level circuit, thus minimizing the delay. First we define two functions. – The “generate” function g i produces 1 when there must be a carry out from position i (i.e., when A i and B i are both 1). g i = A i B i – The “propagate” function p i is true when, if there is an incoming carry, it is propagated (i.e, when A i =1 or B i =1, but not both). p i = A i  B i Then we can rewrite the carry out function: c i+1 = g i + p i c i gigi pipi

Addition and multiplication14 A Note On Propagation We could have defined propagation as A + B instead of A  B – As defined, it captures the case when we propagate but don’t generate I.e., propagation and generation are mutually exclusive – There is no reason that they need to be mutually exclusive – However, if we use  to define propagation, then we can share the XOR gate between the production of the sum bit and the production of the propagation bit

Addition and multiplication15 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?

Addition and multiplication16 A 4-bit carry lookahead adder circuit “carry-out”, not “c-zero”

Addition and multiplication17 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. We can “cascade” carry lookahead adders, just like ripple carry adders. (We’d have to do carry lookahead between the adders too.)

Addition and multiplication18 Cascading Carry Lookahead Adders A0-3 B0-3 A4-7 B4-7 A8-11 B8-11 First Carry-out has a delay of 3 gates Second Carry-out has a delay of 2 gates Third Carry-out has a delay of 2 gates, but S9 has a delay of 3 gates A 4-bit carry lookahed adder has a delay of 4 gates A 12-bit carry lookahead adder has a delay of = 8 gates A 16-bit carry lookahead adder has a delay of = 10 gates S4 S5 S6 S7 S0 S1 S2 S3 S8 S9 S10 S11

Addition and multiplication19 Carry lookahead adders How much faster is a carry lookahead adder? – For a 4-bit adder: There are 4 gates in the longest path of a carry lookahead adder versus 9 gates for a ripple carry adder. – For a 16-bit adder: There are 10 gates in the longest path of a carry lookahead adder versus 33 for a ripple carry adder. – Newer CPUs these days use 64-bit adders! 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.

Addition and multiplication20 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.

Addition and multiplication21 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:

Addition and multiplication22 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

Addition and multiplication23 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!

Addition and multiplication24 A 4x4 multiplier circuit

Addition and multiplication25 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!

Addition and multiplication26 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)

Addition and multiplication27 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.