U of I CS 231 - Addition and multiplication

Unformatted text preview:

Addition and multiplication 1Addition and multiplication• Arithmetic is the most basic thing you can do with a computer, but it’snot as easy as you might expect!• These next few lectures focus on addition, subtraction, multiplicationand 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, andhierarchical, modular design.Addition and multiplication 2Binary addition by hand• You can add two binary numbers one column at a time starting from theright, just as you add two decimal numbers.• But remember that it’s binary. For example, 1 + 1 = 10 and you have tocarry!1 1 1 0 Carry in1 0 1 1 Augend+ 1 1 1 0 Addend1 1 0 0 1 SumThe initial carryin is implicitly 0most significantbit, or MSBleast significantbit, or LSBAddition and multiplication 3Adding 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-bitresult: a sum (the right bit) and a carry out (the left bit).• Here are truth tables, equations, circuit and block symbol.XYCS000 00 1 0 1100 11 1 1 00 + 0 = 00 + 1 = 11 + 0 = 11 + 1 = 10C = XYS = X’ Y + X Y’= X ⊕ YBe careful! Now we’re using +for both arithmetic additionand the logical OR operation.Addition and multiplication 4Adding three bits• But what we really need to do is add three bits: the augend and addend,and the carry in from the right.0 + 0 + 0 = 000 + 0 + 0 = 010 + 1 + 0 = 010 + 1 + 1 = 101 + 0 + 0 = 011 + 0 + 1 = 101 + 1 + 0 = 101 + 1 + 1 = 11X YCinCoutS0 0 0 0 00 0 1 0 10 1 0 0 10 1 1 1 01 0 0 0 11 0 1 1 01 1 0 1 01 1 1 1 1(These are thesame functionsfrom the decoderand mux examples.)1 1 1 01 0 1 1+ 1 1 1 01 1 0 0 1Addition and multiplication 5Full adder equations• A full adder circuit takes three bits of input, and produces a two-bitoutput 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’ 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 ⊕ CinCout= Σm(3,5,6,7) = X’ Y Cin + X Y’ Cin + X Y Cin’ + X Y Cin= (X’ Y + X Y’) Cin + XY(Cin’ + Cin)= (X ⊕ Y) Cin + XYX YCinCoutS0 0 0 0 00 0 1 0 10 1 0 0 10 1 1 1 01 0 0 0 11 0 1 1 01 1 0 1 01 1 1 1 1Addition and multiplication 6Full adder circuit• These things are called half adders and full adders because you canbuild a full adder by putting together two half adders!S = X ⊕ Y ⊕ CinCout= (X ⊕ Y) Cin + XYAddition and multiplication 7A 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 thishierarchical structure—you’d have a 512-row truthtable with five outputs!Addition and multiplication 8An example of 4-bit addition• Let’s try our initial example: A=1011 (eleven), B=1110 (fourteen).1 1 1 0 1 1 0 101. Fill in all the inputs, including CI=01 15. Use C3 to compute CO and S3 (1 + 1 + 1 = 11)02. The circuit produces C1 and S0 (1 + 0 + 0 = 01)113. Use C1 to find C2 and S1 (1 + 1 + 0 = 10)014. Use C2 to compute C3 and S2 (0 + 1 + 1 = 10)0Woohoo! The final answer is 11001 (twenty-five).Addition and multiplication 9Overflow• In this case, note that the answer (11001) is five bits long, while theinputs were each only four bits (1011 and 1110). This is called overflow.• Although the answer 11001 is correct, we cannot use that answer in anysubsequent computations with this 4-bit adder.• For unsigned addition, overflow occurs when the carry out is 1.Addition and multiplication 10Hierarchical adder design• When you add two 4-bit numbers the carry in is always 0, so why doesthe 4-bit adder have a CI input?• One reason is so we can put 4-bit adders together to make even largeradders! This is just like how we put four full adders together to makethe 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 multiplication 11Gate delays• Every gate takes some small fraction of a second between the timeinputs are presented and the time the correct answer appears on theoutputs. This little fraction of a second is called a gate delay.• There are actually detailed ways of calculating gate delays that can getquite complicated, but for this class, let’s just assume that there’s somesmall constant delay that’s the same for all gates.• We can use a timing diagram to show gate delays graphically.xx’10gate delaysAddition and multiplication 12Delays 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 A0, B0 and CI“ripple” leftwards until CO and S3 are produced.• Ripple carry adders are slow!– Our example addition with 4-bit inputs required 5 “steps.”– There is a very long path from A0, B0 and CI to CO and S3.– 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!123456789Addition and multiplication 13A faster way to compute carry outs• Instead of waiting for the carry out from allthe previous stages, we could compute itdirectly with a two-level circuit, thusminimizing the delay.• First we define two functions.– The “generate” function gi produces 1when there must be a carry out fromposition i (i.e., when Ai and Bi are both 1).gi = AiBi– The “propagate” function pi is true when,if there is an incoming carry, it ispropagated (i.e, when Ai=1 or Bi=1, butnot both).pi = Ai ⊕ Bi• Then we can rewrite the carry out function:ci+1= gi + picigipiAiBiCiCi+10 0 0 00 0 1 00 1 0 00 1 1 11 0 0 01 0 1 11 1 0 11 1 1 1Addition and multiplication 14A 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’tgenerate• I.e., propagation and generation are mutually exclusive– There is no reason that they need to be mutually …


View Full Document

U of I CS 231 - Addition and multiplication

Documents in this Course
Counters

Counters

23 pages

Latches

Latches

22 pages

Lecture

Lecture

33 pages

Lecture

Lecture

16 pages

Lecture

Lecture

4 pages

Datapaths

Datapaths

30 pages

Lecture

Lecture

6 pages

Registers

Registers

17 pages

Datapaths

Datapaths

28 pages

Decoders

Decoders

20 pages

Load more
Download Addition and multiplication
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Addition and multiplication and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Addition and multiplication 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?