Tod s Lecture Bsics of Logic Design: Boolen Alger, Logic Gtes Alvin R. Leeck CPS 4 Lecture 8 Homework #2 Due Ferur 3 Outline Review (sseml recursion) Building the uilding locks Logic Design Truth tles, Boolen functions, Gtes nd Circuits Exmples: 2- MUX, Full Adder Reding Appendix B, Chpter 4 CPS 4 2 #include <stdio> Review: The C / C++ code int min ( ) { int i; int sum = ; for(i=; i <= ; i++) sum = sum + i*i ; cout << The nswer is << sum << endl; } Alred did itertive version, recursive version Recursive Exmple.lign 2.text foo: suu $sp, $sp, 32 # stck frme 32 tes sw $r, 2($sp) # sve return ddress sw $fp, 6($sp) # sve old frme pointer ddu $fp, $fp, 6 # set up new frme pointer move $v, $zero # cler return vlue slti $t, $, eq $t, $zero, done # if > do not recurse mul $t, $, $ # i*i $t, 2($sp) # sve sw multipl ddi $, $, # i++ jl foo # recurse lw $t, 2($sp) # restore multipl dd $v, $v, $t # sum += i*i done: lw $fp, 6($sp) # restore old frme ptr lw $r, 2($sp) # restore return ddress ddu $sp, $sp, 32 # remove frme j $r CPS 4 3 CPS 4 4 Recursive Exmple (Continued) Recursive Exmple (Continued).text.glol min min: suu $sp, $sp, 32 # stck frme 32 tes sw $r, 2($sp) # sve return ddress sw $fp, 6($sp) # sve old frme pointer ddu $fp, $fp, 6 # set up new frme pointer.dt mstr:.sciiz "The nswer is " endl:.sciiz "\n" li $v, 4 # 4 = print string l $, mstr # lod ddress of string sscll # print string li $, # initilize $i jl foo # cll foo move $, $v # put result in $ li $v, # = print int sscll # print int li $v, 4 # 4 = print string l $, endl # lod ddress of endl sscll # print string This is on course we pge (code ) lw $fp, 6($sp) # restore old frme ptr lw $r, 2($sp) # restore return ddress ddu $sp, $sp, 32 # remove frme j $r CPS 4 5 CPS 4 6
The Big Picture Wht We ve Done, Where We re Going The Five Clssic Components of Computer Processor/CPU Control Dtpth Memor Input Output Top Down Appliction Compiler Operting Sstem CPU Memor I/O sstem Digitl Design Circuit Design Firmwre Softwre Interfce Between HW nd SW Instruction Set Architecture, Memor, I/O Hrdwre Bottom UP to CPU CPS 4 7 CPS 4 8 Digitl Design Boolen Alger Logic Design, Switching Circuits, Digitl Logic Recll: Everthing is uilt from trnsistors A trnsistor is switch It is either on or off On or off cn represent True or Flse Need method to reson out complex expressions Given unch of its Is this instruction lw or eq? Wht register do I red? How do I dd two numers? Boolen functions hve rguments tht tke two vlues ({T,F} or {,}) nd the return single or set of ({T,F} or {,}) vlue(s). Boolen functions cn lws e represented tle clled Truth Tle Exmple: F: {,} 3 -> {,} 2 c f f 2 CPS 4 9 CPS 4 NOT() Boolen Functions Exmple Boolen Functions: NOT, AND, OR, XOR,... AND(,) OR(,) Boolen Functions nd Expressions Boolen lger nottion: Use * for AND, + for OR, ~ for NOT. Not is lso written s A nd A Using the ove nottion one cn write Boolen expressions for functions F(A, B, C) = (A * B) + (~A * C) XOR(,) XNOR(,) NOR(,) One cn evlute the Boolen expression with ll possile rgument vlues to construct truth tle. Wht is truth tle for F? CPS 4 CPS 4 2
Boolen Function Simplifiction Boolen Function Simplifiction Boolen expressions cn e simplified using the following rules: A*A = A A* = A* = A A*~A = A+A = A A+ = A A+ = A+~A = A*B = B*A A*(B+C) = (B+C)*A = A*B + A*C c f f 2 f = ~*~*c + ~**c + *~*c + **c f 2 = ~*~*~c + ~*~*c + **~c + **c Simplif these functions... CPS 4 4 CPS 4 5 Boolen Functions nd Expressions Boolen Functions nd Expressions The Fundmentl Theorem of Boolen Alger: Ever Boolen function cn e written in disjunctive norml form s n OR of ANDs (Sum-of products) of it s rguments or their complements. Proof: Write the truth tle, construct sum-ofproduct from the tle. XNOR(,) XNOR = (~ * ~) + ( * ) Exmple-2: c f f 2 f = ~*~*c + ~**~c + *~*~c + **c f 2 = ~*~*~c + ~*~*c + **~c + **c CPS 4 7 CPS 4 8 DeMorgn s Lws Boolen Gtes ~(A+B) = ~A * ~B ~(A*B) = ~A + ~B Exmple: Gtes re electronic devices tht implement simple Boolen functions Exmples ~C*~A*B + ~C*A*~B + C*A*B + C*~A*~B Use onl XOR to represent this function AND(,) OR(,) NOT() XOR(,) NAND(,) NOR(,) XNOR(,) CPS 4 9 CPS 4 2
Relit Check Bsic Boolen Gte -4 Trnsistors Pentium III Processor Core 9.5 Million Trnsistors Totl: 28 Million Trnsistors Pentium 4 Totl: 42 Million Trnsistors Boolen Functions, Gtes nd Circuits Circuits re mde from network of gtes. (function compositions). XOR(,) F = ~* + ~* XOR(,) F CPS 4 2 CPS 4 22 Digitl Design Exmples Design Exmple Input: 2 its representing n unsigned numer (n) Output: n 2 s unsigned inr numer Input: 2 its representing n unsigned numer (n) Output: 3-n s unsigned inr numer Consider mchine with 4 registers Given 2-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 23 CPS 4 24 Circuit Exmple: Decoder Circuit Exmple: 2x MUX Q3 Multiplexor (MUX) selects from one of mn inputs Q2 Q I I Q Q Q 2 Q 3 s MUX(A, B, S) = (A * S) + (B * ~S) Q B Gte Gte 3 Y = (A * S) + (B * ~S) A Gte 2 S I I CPS 4 25 CPS 4 26
Exmple 4x MUX Arithmetic nd Logicl Opertions in ISA c d c d 3 2 Wht opertions re there? How do we implement them? Consider -it Adder s s 2 S CPS 4 27 CPS 4 28 Summr Boolen Alger & functions Logic gtes (AND, OR, NOT, etc) Multiplexors Reding Appendix B, Chpter 4 CPS 4 29