CPS 4 Computer Orgniztion nd Progrmming Lecture : Boolen Alger & gtes. Roert Wgner CPS4 BA. RW Fll 2 Overview of Tody s Lecture: Truth tles, Boolen functions, Gtes nd Circuits Krnugh mps for simplifying Boolen equtions Exmples: 2- MUX, Red Appendix B CPS4 BA.2 RW Fll 2 How Computers Relly Work Computers mnipulte sequences of s nd s in wys tht simulte ordinry rithmetic, nd comprisons Computer hrdwre uses Boolen opertions, lso clled Logic functions to do this These mthemticl functions operte on 2 vlues, interpreted s True (T) nd Flse (F), or s nd Bsic Boolen functions cn e implemented y circuits whose inputs nd outputs re voltges representing nd. The voltges involved cn e oserved -- cn light lmp, while leves the lmp unlit. Or, the Boolen vlue on wire cn set displyed pixel on or off. CPS4 BA.3 RW Fll 2
Boolen Functions nd Gtes Boolen functions hve rguments tht ech tke one of two vlues (clled either {T,F} or {,}). Ech returns one ({T,F} or {,}) vlue, or vector of such vlues. Boolen functions cn lwys e represented y tle clled: Truth Tle which gives the nswer, for every input comintion. Exmple: F: {,} 3 -> {,} 2 c f f 2 CPS4 BA.4 RW Fll 2 Boolen Functions nd Gtes (Cont.) Exmples: Boolen functions: NOT, AND, OR, XOR,... NOT() AND(,) OR(,) XOR(,) XNOR(,) NOR(,) CPS4 BA.5 RW Fll 2 Boolen Functions nd Gtes (Cont.) Gtes re electronic devices tht implement simple Boolen functions: Exmples (gte shpe indictes the function the gte computes): AND(,) OR(,) NOT() XOR(,) NAND(,) NOR(,) XNOR(,) CPS4 BA.6 RW Fll 2
Boolen Expressions Boolen lger nottion: Use: * for AND, + for OR, ~ for NOT. Using the ove nottion one could write Boolen expressions for functions: Exmple: F(A, B, C) = (A * B) + ( ~A*C) CPS4 BA.7 RW Fll 2 Boolen Functions nd Expressions One cn evlute the Boolen expression with ll possile rgument vlues to construct truth tle. Exmple: F(A, B, C) = (A * B) + ( ~A*C) A B C F CPS4 BA.8 RW Fll 2 Boolen functions simplifiction Boolen expressions could e simplified y using the following rules: A*A = A A+A = A ~~A = A A* = A+ = A* = A A+ = A A*~A = A+~A= A*B = B*A A+B = B+A A*(B+C) = A*B + A*C A+(B*C) = (A+B)*(B+C) ~(A+B) = ~A * ~B ~(A*B) = ~A + ~B CPS4 BA.9 RW Fll 2
Boolen Functions simplifiction Exmple: c f f 2 f = ~*~*c + ~**c + *~*c + **c f 2 = ~*~*~c + ~*~*c + **~c + **c CPS4 BA. RW Fll 2 Boolen Function Simplifiction f = ~*~*c + ~**c + *~*c + **c = ~*(~*c +*c) +*(~*c+*c) = ~*c*(~+) + *c*(~+) = ~*c + *c = c*(~+) = c f 2 = ~*~*~c + ~*~*c + **~c + **c = ~*(~*~c + ~*c) + *(*~c + *c) = ~*~*(c+~c) + **(~c+c) = ~*~ + * CPS4 BA. RW Fll 2 Krnugh Mps Grphicl device for simplifying Boolen equtions For 4-vrile eqution: Enter desired truth tle in 4 y 4 mtrix, whose rows re leled with ll comintions of vlues of 2 vriles, nd whose cols re leled with other vrile vlues Include Don t Cre entries s x Row / Column order: One vrile vlue chnges etween djcent rows, nd etween djcent columns Ech rectngle contining only T or x entries, whose side-lengths re, 2, or 4 represents simplified term -- identified y ANDing vriles or their complements which re constnt over cells in the rectngle. OR enough terms together to cover ll T entries in tle. CPS4 BA.2 RW Fll 2
Krnugh Mp Exmple CD: FF FT TT TF AB FF T x T FT x T x TT x x ~A*~D B*C TF ~A* ~D + B* C CPS4 BA.3 RW Fll 2 Boolen Functions nd Expressions The Fundmentl Theorem of Boolen Alger: Every Boolen function cn e written in disjunctive norml form s n OR of ANDs (Sumof products) of it s rguments or their complements. Proof: Write the truth tle, construct sum-ofproduct from the tle. Exmple: XNOR(,) XNOR = (~ * ~) + ( * ) CPS4 BA.4 RW Fll 2 Boolen Functions nd Boolen Expressions Exmple-2: c f f 2 f = ~*~*c + ~**~c + *~*~c + **c f 2 = ~*~*~c + ~*~*c + **~c + **c CPS4 BA.5 RW Fll 2
Boolen Functions, Gtes nd Circuits Circuits re mde from network of gtes. (function compositions). Exmple: XOR(,) F = ~* + ~* F CPS4 BA.6 RW Fll 2 Circuit Exmple: 2x MUX s y B Gte Gte 3 Y = (A * S) + (B * ~S) A Gte 2 S ~(~A*~B) = ~~A + ~~B = A+B CPS4 BA.7 RW Fll 2 Exmple 4x MUX c d y c d 3 2 y s s 2 S CPS4 BA.8 RW Fll 2
Circuit Exmple: Selector Q 3 Q 2 Q Q I I Q Q Q 2 Q 3 Sets just ONE output True -- the one indexed y the vlue of I I converted to deciml CPS4 BA.9 I I RW Fll 2 Cin Sum + Cout C in Sum C out CPS4 BA.2 RW Fll 2 Exmple: 4-it dder S3 S2 S S C out 3 3 2 2 CPS4 BA.2 RW Fll 2
Exmple: Adder/Sutrctor S3 S2 S S C out Add/Su 3 3 2 2 (XOR gtes): A xor B is (A?~B:B) CPS4 BA.22 RW Fll 2 Overflow Detection: exmples Exmple: 2 (= 53 ) + 2 (= 42 ) 2 (=-33 ) Exmple3: 2 (= 53 ) + 2 (=-22 ) 2 (= 3 ) Exmple2: 2 (=-43 ) + 2 (=-54 ) 2 (= 3 ) Exmple4: 2 (= 2 ) + 2 (= 42 ) 2 (= 63 ) CPS4 BA.23 RW Fll 2 Overflow Detection nd Crries In Addition nd Sutrction opertions, Overflow occurs when two numer of sme sign re dded, nd result hs different sign. Must e function of wht hppens in high-order full-dder A 3 B 3 Cin 3 S 3 Cout 3 OVF Cin= Cout F Y T N F Y F Y F Y F Y T N F Y CPS4 BA.24 RW Fll 2
Add/Sutrct With Overflow detection Overflow S n- S n- 2 S S Add/Su n- n- n- 2 n- 2 CPS4 BA.25 RW Fll 2 MIPS ALU Slice Cin 3 2 Q A F Q + - - NOT - 2 OR - 3 AND Add/su 2 Cout Add/su CPS4 BA.26 RW Fll 2 F The MIPS ALU Overflow = Zero Q n- Q n-2 Q Q ALU Slice ALU Slice ALU Slice ALU Slice n- n- n-2 n-2 CPS4 BA.27 RW Fll 2