Bsics of Logic Design Arithmetic Logic Unit (ALU) CPS 4 Lecture 9 Tody s Lecture Homework #3 Assigned Due Mrch 3 Project Groups ssigned & posted to lckord. Project Specifiction is on We Due April 9 Building the uilding locks Outline Review Digitl uilding locks An Arithmetic Logic Unit (ALU) Reding Appendix B, Chpter 3 CPS 4
Review: Digitl Design Logic Design, Switching Circuits, Digitl Logic Recll: Everything is uilt from trnsistors A trnsistor is switch It is either on or off On or off cn represent True or Flse Given unch of its ( or ) Is this instruction lw or eq? Wht register do I red? How do I dd two numers? Need method to reson out complex expressions CPS 4 3 Review: Boolen Functions Boolen functions hve rguments tht tke two vlues ({T,F} or {,}) nd they return single or set of ({T,F} or {,}) vlue(s). Boolen functions cn lwys e represented y tle clled Truth Tle Exmple: F: {,}3 -> {,} c f f CPS 4 4
Review: Boolen Functions nd Expressions F(A, B, C) = (A * B) + (~A * C) A B C F CPS 4 5 Review: Boolen Gtes Gtes re electronics devices tht implement simple Boolen functions Exmples AND(,) OR(,) NOT() XOR(,) NAND(,) NOR(,) XNOR(,) CPS 4 6
Boolen Functions, Gtes nd Circuits Circuits re mde from network of gtes. (function compositions). XOR(,) F = ~* + ~* XOR(,) F CPS 4 7 Digitl Design Exmples Input: its representing n unsigned numer (n) Output: n s unsigned inry numer Input: its representing n unsigned numer (n) Output: 3-n s unsigned inry numer CPS 4 8
More Design Exmples X is 3-it quntity. Write logic function tht is true if nd only if X contins t lest two s.. Implement the logic function from prolem. using only AND, OR nd NOT gtes. (Note there re no constrints on the numer of gte inputs.) By implement, I men drw the circuit digrm. 3. Write logic function tht is true if nd only if X, when interpreted s n unsigned inry numer, is greter thn the numer 5. 4. Implement the logic function from prolem 3. using only AND, OR nd NOT gtes. (Note there re no constrints on the numer of gte inputs.) CPS 4 9 Prity Exmple The prity code of inry word counts the numer of ones in word. If there re n even numer of ones the prity code is, if there re n odd numer of ones the prity code is. For exmple, the prity of is, nd the prity of is. Construct the truth tle for function tht computes the prity of four-it word. Implement this function using AND, OR nd NOT gtes. (Note there re no constrints on the numer of gte inputs.) CPS 4
Design Exmple Consider mchine with 4 registers Given -it input (register specifier, I, I ) Wnt one of 4 output its (O 3 -O ) to e E.g., llows single register to e ccessed Wht is the circuit for this? CPS 4 Circuit Exmple: Decoder Q 3 I I Q Q Q Q3 Q Q Q I I CPS 4
Circuit Exmple: x MUX Multiplexor (MUX) selects from one of mny inputs y MUX(A, B, S) = (A * S) + (B * ~S) s B Gte Gte 3 Y = (A * S) + (B * ~S) A Gte S CPS 4 3 Exmple 4x MUX c d y c d 3 y s s S CPS 4 4
Arithmetic nd Logicl Opertions in ISA Wht opertions re there? How do we implement them? Consider -it Adder CPS 4 5 Truth Tle for -it Addition + C in Sum C out Wht is the circuit for Sum nd for Cout? CPS 4 6
A -it Cin Sum + Cout C in Sum C out CPS 4 7 Exmple: 4-it dder S3 S S S C out C in 3 3 CPS 4 8
ALU Slice (Almost) Cin 3 Q F Q + NOT OR 3 AND Adder Cout F CPS 4 9 Sutrction How do we perform integer sutrction? Wht is the HW? CPS 4
ALU Slice Cin 3 B inv F Q + - - NOT - OR - 3 AND Q Su B invert Adder Cout F CPS 4 Exmple: Adder/Sutrcter S3 S S S C out C in Add/Su 3 3 Add/Su = => Addition Add/Su = => Sutrction CPS 4
Exmple: (= 53 ) + (= 4 ) (=-33 ) Overflow Exmple: (=-43 ) + (=-54 ) (= 3 ) Exmple3: (= 53 ) + (=- ) (= 3 ) Exmple4: (= ) + (= 4 ) (= 63 ) CPS 4 3 Add/Sutrct With Overflow detection OVERFLOW S n- S n- S S Add/Su n- n- n- n- CPS 4 4
The new ALU Slice Cin 3 Q A F Q + - - NOT - OR - 3 AND Add/su Add/su Cout F CPS 4 5 The ALU Overflow = Zero Q n- Q n- Q Q ALU Slice ALU Slice ALU Slice ALU Slice ALU control n- n- n- n- CPS 4 6
Astrction: The ALU Generl structure Two opernd inputs Control inputs ALU Opertion Input A Input B ALU Zero Result Overflow Crry Out CPS 4 7 The Shift Opertion Consider n 8-it mchine How do I implement the shift opertion? CPS 4 8
Shifter 7 6 5 4 3 Shift- Shift- Shift-4 Q7 Q6 Q5 Q4 Q3 Q Q Q CPS 4 9 Summry thus fr Given Boolen function, generte circuit tht relizes the function. Constructed circuits tht cn dd nd sutrct. The ALU: circuit tht cn dd, sutrct, detect overflow, compre, nd do it-wise opertions (AND, OR, NOT) Shifter Next up: Storge Elements: Registers, Ltches, Buses CPS 4 3