This action might not be possible to undo. Are you sure you want to continue?

• •

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.

•

September 29, 2003

Addition and multiplication

1

**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, 1 + 1 = 10 and you have to carry! The initial carry in is implicitly 0

1

+ 1

1 1 1 1

1 0 1 0

0 1 1 0

1 0 1

Carry in Augend Addend Sum

**most significant bit, or MSB
**

September 29, 2003

**least significant bit, or LSB
**

2

Addition and multiplication

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

) September 29.Adding three bits • But what we really need to do is add three bits: the augend and addend. 2003 Addition and multiplication 4 . 1 + 1 S 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 1 +0 +0 +1 +1 +0 +0 +1 +1 +0 +0 +0 +1 +0 +1 +0 +1 = 00 = 01 = 01 = 10 = 01 = 10 = 10 = 11 1 1 1 1 1 0 1 0 0 1 1 0 1 0 1 X 0 0 0 0 1 1 1 1 Y 0 0 1 1 0 0 1 1 Cin 0 1 0 1 0 1 0 1 Cout 0 0 0 1 0 1 1 1 (These are the same functions from the decoder and mux examples. and the carry in from the right.

7) = X’ Y’ Cin + X’ Y Cin’ + X Y’ Cin’ + X Y Cin = X’ (Y’ Cin + Y Cin’) + X (Y’ Cin’ + Y Cin) = X’ (Y Cin) + X (Y Cin)’ = X Y Cin Cout = m(3.6. X 0 0 0 0 1 1 1 1 Y 0 0 1 1 0 0 1 1 Cin 0 1 0 1 0 1 0 1 Cout 0 0 0 1 0 1 1 1 S 0 1 1 0 1 0 0 1 S = m(1.4.5.7) = X’ Y Cin + X Y’ Cin + X Y Cin’ + X Y Cin = (X’ Y + X Y’) Cin + XY(Cin’ + Cin) = (X Y) Cin + XY September 29. we get the equations shown here.Full adder equations • • A full adder circuit takes three bits of input. Using Boolean algebra. and produces a two-bit output consisting of a sum and a carry out. – We used algebra because you can’t easily derive XORs from K-maps. – XOR operations simplify the equations a bit.2. 2003 Addition and multiplication 5 .

2003 Addition and multiplication 6 .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 Cin Cout = (X Y) Cin + XY September 29.

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

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

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

Here is an 8-bit adder.Hierarchical adder design • • • When you add two 4-bit numbers the carry in is always 0. as we’ll see next week. 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. for example. 2003 . Addition and multiplication 10 September 29. • CI is also useful for subtraction.

2003 Addition and multiplication 11 . but for this class. This little fraction of a second is called a gate delay. We can use a timing diagram to show gate delays graphically. There are actually detailed ways of calculating gate delays that can get quite complicated. let’s just assume that there’s some small constant delay that’s the same for all gates. 1 0 x x’ gate delays September 29.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.

The longest path would have 129 gates! 1 9 8 7 6 5 4 3 2 September 29. – Imagine a 64-bit adder. Ripple carry adders are slow! – Our example addition with 4-bit inputs required 5 ―steps. B0 and CI to CO and S3. B0 and CI ―ripple‖ leftwards until CO and S3 are produced. This is called a ripple carry adder.‖ – There is a very long path from A0. because the inputs A0. – For an n-bit ripple carry adder. the longest path has 2n+1 gates.Delays in the ripple carry adder • • • The diagram below shows a 4-bit adder completely drawn out. 2003 Addition and multiplication 12 .

if there is an incoming carry. we could compute it directly with a two-level circuit. it is propagated (i. First we define two functions. when Ai=1 or Bi=1. pi = Ai Bi Ai 0 0 0 0 1 1 1 1 Bi 0 0 1 1 0 0 1 1 Ci 0 1 0 1 0 1 0 1 Ci+1 0 0 0 1 0 1 1 1 13 • Then we can rewrite the carry out function: ci+1 = gi + pici September 29. thus minimizing the delay. 2003 Addition and multiplication .. when Ai and Bi are both 1).A faster way to compute carry outs • Instead of waiting for the carry out from all the previous stages. but not both).e.e. • gi pi – gi = AiBi The ―propagate‖ function pi is true when. – The ―generate‖ function gi produces 1 when there must be a carry out from position i (i.

2003 .Algebraic carry out hocus-pocus • Let’s look at the carry out equations for specific bits. Addition and multiplication 14 September 29. using the general equation from the previous page ci+1 = gi + pici: c1 = g0 + p0c0 c2 = g1 + p1c1 = g1 + p1(g0 + p0c0) = g1 + p1g0 + p1p0c0 c3 = g2 + p2c2 = g2 + p2(g1 + p1g0 + p1p0c0) = g2 + p2g1 + p2p1g0 + p2p1p0c0 Ready to see the circuit? c4 = g3 + p3c3 = g3 + p3(g2 + p2g1 + p2p1g0 + p2p1p0c0) = g3 + p3g2 + p3p2g1 + p3p2p1g0 + p3p2p1p0c0 • These expressions are all sums of products. so we can use them to make a circuit with only a two-level delay.

not ―c-zero‖ September 29. 2003 Addition and multiplication 15 .A 4-bit carry lookahead adder circuit ―carry-out‖.

– Newer CPUs these days use 64-bit adders. while a ripple carry adder’s delay grows linearly.Carry lookahead adders • • • • This is called a carry lookahead adder. – But if we do the cascading properly. 129 gates! The delay of a carry lookahead adder grows logarithmically with the size of the adder. There are 4 gates in the longest path of a carry lookahead adder. versus 9 gates for a ripple carry adder. 2003 . Carry lookahead adders are faster but more complex. just like ripple carry adders. Ripple carry adders are simpler. (We’d have to do carry lookahead between the adders too. as opposed to 33 for a ripple carry adder. but slower. not much. We can ―cascade‖ carry lookahead adders. The thing to remember about this is the trade-off between complexity and performance. we reduced the number of levels in the circuit and sped things up. Addition and multiplication 16 • • September 29.) How much faster is this? – For a 4-bit adder. a 16-bit carry lookahead adder could have only 8 gates in the longest path. By adding more hardware. That’s 12 vs.

Carry lookahead adders can be much faster than ripple carry adders. We can get fancy by using two-level circuitry to compute the carry-in for each adder.) We can string several full adders together to get adders that work for numbers with more than one bit. • • September 29. 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. This is called carry lookahead. 2003 Addition and multiplication 17 . we get a ripple carry adder.Addition summary • We can use circuits call full-adders to add three bits together to produce a two-bit output. By connecting the carry-out of one adder to the carry-in of the next.

we can do multiplication also. Remember that the AND operation is equivalent to multiplication on two bits: • a 0 0 1 1 b 0 1 0 1 ab 0 0 0 1 a 0 0 1 1 b ab 0 1 0 1 0 0 0 1 September 29.Multiplication • Multiplication can’t be that hard! – It’s just repeated addition. – If we have adders. 2003 Addition and multiplication 18 .

– Even though the product has up to 8 bits. using three adders. 2003 Addition and multiplication 19 . the partial products are always either 0000 or the multiplicand (1101 in this example). like the partial products themselves.Binary multiplication example x 1 0 0 1 0 0 1 1 1 0 0 1 1 0 1 0 1 1 0 0 Multiplicand Multiplier Partial products + 0 1 1 0 0 1 1 0 0 1 0 Product • • Since we always multiply by either 0 or 1. – We can add them in pairs. we can use 4-bit adders if we ―stagger‖ them leftwards. September 29. There are four partial products which are added to form the result.

we’ll need full adders. For a 2-bit by 2-bit multiplier. not carries! B1 A1 A0B1 A1B0 C1 B0 A0 A0B0 C0 • x + C3 A1B1 C2 September 29.A 2x2 binary multiplier • • The AND gates produce the partial products. In general. we can just use two half adders to sum the partial products. Here C3-C0 are the product. 2003 Addition and multiplication 20 . though.

2003 Addition and multiplication 21 .A 4x4 multiplier circuit September 29.

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

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

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

Sign up to vote on this title

UsefulNot useful- 09-AdditionMultiplication
- 09-AdditionMultiplication
- 09 AdditionMultiplication Sol (2)
- 09-AdditionMultiplication
- unit18
- Unit 2.ppt
- mul 1.pdf
- Configruable Booth Multiplier
- Mu Lit Pliers Dividers Supp4
- design of adder
- 09_Arithmetric_p2
- Design and Analysis of High Speed, Area Optimized 32x32-Bit Multiply Accumulate Unit Based on Vedic Mathematics
- Arithematic Unit
- C2. Fixed Point and Floating Point Operations
- Shawn Present
- Full Text 01
- Booth
- Unit5-HVRA.pdf
- Booth 4 8 Radix
- Pipelining Multiplier
- Design of Improved Array Multiplier By
- 10509019_final
- Area efficient Short Bit Width Two’s Compliment Multiplier Using CSA
- Simran Thesis
- ijcsit2011020553
- enhanced seperable data hiding
- Com Bi National Multiplier
- Unit2 Arithmetics
- Lecture 3 8405 Computer architecture
- Vedic
- 09-AdditionMultiplication