DOC PREVIEW
U of I CS 231 - Arithmetic-logic units

This preview shows page 1-2-22-23 out of 23 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Arithmetic-logic unitsThe four-bit adderIt’s the adder-subtractor again!The multi-talented adderModifying the adder inputsSome more possible functionsThe role of CITable of arithmetic functionsMapping the table to an adderBuilding the input logicPrimitive gate-based input logicPrimitive gate implementationBitwise operationsBitwise operations in programmingBitwise operations in networkingDefining a logic unitOur simple logic unitCombining the arithmetic and logic unitsOur ALU function tableA complete ALU circuitComments on the multiplexerThe completed ALUArithmetic summaryArithmetic-logic units 1Arithmetic-logic units•An arithmetic-logic unit, or ALU, performs many different arithmetic and logic operations. The ALU is the “heart” of a processor—you could say that everything else in the CPU is there to support the ALU.•Here’s the plan:–We’ll show an arithmetic unit first, by building off ideas from the adder-subtractor circuit.–Then we’ll talk about logic operations a bit, and build a logic unit.–Finally, we put these pieces together using multiplexers.•We show the same examples as from the book (pp. 360-365), but things are re-labeled to be clearer in LogicWorks. Cin and S0 are also treated a little differently.Arithmetic-logic units 2The four-bit adder•The basic four-bit adder always computes S = A + B + CI.•But by changing what goes into the adder inputs A, B and CI, we can change the adder output S.•This is also what we did to build the combined adder-subtractor circuit.Arithmetic-logic units 3It’s the adder-subtractor again!•Here the signal Sub and some XOR gates alter the adder inputs.–When Sub = 0, the adder inputs A, B, CI are Y, X, 0, so the adder produces G = X + Y + 0, or just X + Y.–When Sub = 1, the adder inputs are Y’, X and 1, so the adder output is G = X + Y’ + 1, or the two’s complement operation X - Y.Arithmetic-logic units 4The multi-talented adder•So we have one adder performing two separate functions.•“Sub” acts like a function select input which determines whether the circuit performs addition or subtraction.•Circuit-wise, all “Sub” does is modify the adder’s inputs A and CI.Arithmetic-logic units 5Modifying the adder inputs•By following the same approach, we can use an adder to compute other functions as well.•We just have to figure out which functions we want, and then put the right circuitry into the “Input Logic” box .Arithmetic-logic units 6Some more possible functions•We already saw how to set adder inputs A, B and CI to compute eitherX + Y or X - Y.•How can we produce the increment function G = X + 1?•How about decrement: G = X - 1?•How about transfer: G = X?(This can be useful.)This is almost the same as theincrement function!One way: Set A = 0000, B = X, and CI = 1A = 1111 (-1), B = X, CI = 0A = 0000, B = X, CI = 0Arithmetic-logic units 7The role of CI•The transfer and increment operations have the same A and B inputs, and differ only in the CI input.•In general we can get additional functions (not all of them useful) by using both CI = 0 and CI = 1.•Another example:–Two’s-complement subtraction is obtained by setting A = Y’, B = X, and CI = 1, so G = X + Y’ + 1.–If we keep A = Y’ and B = X, but set CI to 0, we get G = X + Y’. This turns out to be a ones’ complement subtraction operation.Arithmetic-logic units 8Table of arithmetic functions•Here are some of the different possible arithmetic operations.•We’ll need some way to specify which function we’re interested in, so we’ve randomly assigned a selection code to each operation.S2 S1 S0 Arithmetic operation 0 0 0 X (transf er) 0 0 1 X + 1 (increment) 0 1 0 X + Y (add) 0 1 1 X + Y + 1 1 0 0 X + Y’ (1C subtraction) 1 0 1 X + Y’ + 1 (2C subtraction) 1 1 0 X – 1 (decrement) 1 1 1 X (transf er)Arithmetic-logic units 9Mapping the table to an adder•This second table shows what the adder’s inputs should be for each of our eight desired arithmetic operations.–Adder input CI is always the same as selection code bit S0.–B is always set to X.–A depends only on S2 and S1.•These equations depend on both the desired operations and the assignment of selection codes.Selection code Desired arithmetic operation Required adder inputsS2S1S0G (A + B + CI ) A B CI0 0 0 X (transf er) 0000 X 00 0 1 X + 1 (increment) 0000 X 10 1 0 X + Y (add) Y X 00 1 1 X + Y + 1 Y X 11 0 0 X + Y’ (1C subtraction) Y’ X 01 0 1 X + Y’ + 1 (2C subtraction) Y’ X 11 1 0 X – 1 (decrement) 1111 X 01 1 1 X (transf er) 1111 X 1Arithmetic-logic units 10Building the input logic•All we need to do is compute the adder input A, given the arithmetic unit input Y and the function select code S (actually just S2 and S1).•Here is an abbreviated truth table:•We want to pick one of these four possible values for A, depending on S2 and S1.S2S1A0 0 00000 1 Y1 0 Y’1 1 1111Arithmetic-logic units 11Primitive gate-based input logic•We could build this circuit using primitive gates.•If we want to use K-maps for simplification, then we should first expand out the abbreviated truth table.–The Y that appears in the output column (A) is actually an input.–We make that explicit in the table on the right.•Remember A and Y are each 4 bits long! S2S1A0 0 00000 1 Y1 0 Y’1 1 1111S2S1YiAi0 0 0 00 0 1 00 1 0 00 1 1 11 0 0 11 0 1 01 1 0 11 1 1 1Arithmetic-logic units 12Primitive gate implementation•From the truth table, we can find an MSP:•Again, we have to repeat this once for each bit Y3-Y0, connecting to the adder inputs A3-A0.•This completes our arithmetic unit.S10 0 1 0S21 0 1 1YiAi = S2Yi’ + S1YiArithmetic-logic units 13Bitwise operations•Most computers also support logical operations like AND, OR and NOT, but extended to multi-bit words instead of just single bits.•To apply a logical operation to two words X and Y, apply the operation on each pair of bits Xi and Yi:•We’ve already seen this informally in two’s-complement arithmetic, when we talked about “complementing” all the bits in a number.1 0 1 1AND 1 1 1 01 0 1 01 0 1 1OR 1 1 1 01 1 1 11 0 1 1XOR 1 1 1 00 1 0 1Arithmetic-logic units 14•Languages like C, C++ and Java provide bitwise logical operations:& (AND) | (OR) ^ (XOR) ~ (NOT)•These operations treat each integer as a bunch of individual bits:13 & 25 = 9 because 01101 & 11001 = 01001•They are not the same as the operators &&, || and !, which


View Full Document

U of I CS 231 - Arithmetic-logic units

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 Arithmetic-logic units
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 Arithmetic-logic units 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 Arithmetic-logic units 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?