Computer Architecture Lecture : Combinational Circuits Previous two lectures.! TOY machine. Net two lectures.! Digital circuits. George Boole (85 864) Claude Shannon (96 2) Culminating lecture.! Putting it all together and building a TOY machine. COS26: General Computer Science http://www.cs.princeton.edu/~cos26 2 Digital Circuits Wires What is a digital sstem?! Digital: signals are or.! Analog: signals var continuousl. Wh digital sstems?! Accurac and reliabilit.! Staggeringl fast and cheap. Basic abstractions.! On, off.! Switch that can turn something on or off. Wires.! Propagate logical values from place to place.! Signals "flow" from left to right. A drawing convention, sometimes violated Actuall: flow from producer to consumer(s) of signal Digital circuits and ou.! Computer microprocessors.! Antilock brakes.! Cell phones. Input Output 3 4
Logic Gates Multiwa AND Gates Logical gates.! Fundamental building blocks. AND(,, 2, 3, 4, 5, 6, 7 ).! if all inputs are.! otherwise. ' NOT AND OR 5 6 Multiwa OR Gates Boolean Algebra OR(,, 2, 3, 4, 5, 6, 7 ).! if at least one input is.! otherwise. Histor.! Developed b Boole to solve mathematical logic problems (847).! Shannon first applied to digital circuits (937). Basics.! Boolean variable: value is or.! Boolean function: function whose inputs and outputs are,. Relationship to circuits.! Boolean variables: signals.! Boolean functions: circuits. 7 8
Truth Table Truth Table for Functions of 2 Variables Truth table.! Sstematic method to describe Boolean function.! One row for each possible input combination.! N inputs! 2 N rows. Truth table.! 6 Boolean functions of 2 variables. ever 4-bit value represents one Truth Table for All Boolean Functions of 2 Variables AND Truth Table AND(, ) ZERO AND XOR Truth Table for All Boolean Functions of 2 Variables NOR EQ ' ' NAND OR ONE AND 9 Truth Table for Functions of 3 Variables Universalit of AND, OR, NOT Truth table.! 6 Boolean functions of 2 variables. ever 4-bit value represents one! 256 Boolean functions of 3 variables. ever 8-bit value represents one! 2^(2^N) Boolean functions of N variables! Some Functions of 3 Variables z AND OR MAJ ODD An Boolean function can be epressed using AND, OR, NOT.! "Universal."! XOR(,) = ' ' Epressing XOR Using AND, OR, NOT ' ' ' ' ' ' XOR Notation ' Eercise: {AND, NOT}, {OR, NOT}, {NAND}, {AND, XOR} are universal. Meaning NOT AND OR 2
Sum-of-Products Translate Boolean Formula to Boolean Circuit An Boolean function can be epressed using AND, OR, NOT.! Sum-of-products is sstematic procedure. form AND term for each in truth table of Boolean function OR terms together Use sum-of-products form.! XOR(, ) = ' '. Epressing MAJ Using Sum-of-Products z MAJ 'z 'z z' z 'z 'z z' z 3 4 Translate Boolean Formula to Boolean Circuit Simplification Using Boolean Algebra Use sum-of-products form.! MAJ(,, z) = 'z 'z z' z. Man possible circuits for each Boolean function.! Sum-of-products not necessaril optimal in: number of gates (space) depth of circuit (time)! MAJ(,, z) = 'z 'z z' z = z z. size = 8, depth = 3 size = 4, depth = 2 5 6
Epressing a Boolean Function Using AND, OR, NOT ODD Parit Circuit Ingredients.! AND gates.! OR gates.! NOT gates.! Wire. ODD(,, z).! if odd number of inputs are.! otherwise. Epressing ODD Using Sum-of-Products Instructions.! Step : represent input and output signals with Boolean variables.! Step 2: construct truth table to carr out computation.! Step 3: derive (simplified) Boolean epression using sum-of products.! Step 4: transform Boolean epression into circuit. z ODD ''z 'z' 'z' z ''z 'z' 'z' z 7 8 ODD Parit Circuit Let's Make an Adder Circuit ODD(,, z).! if odd number of inputs are.! otherwise. Goal: = z for 4-bit integers.! We build 4-bit adder: 9 inputs, 4 outputs.! Same idea scales to 28-bit adder.! Ke computer component. 2 4 8 7 3 5 7 9 6 6 6 Step.! Represent input and output in binar. 3 2 3 2 c z 3 z 2 z z 3 2 3 2 z 3 z 2 z z 9 2
Let's Make an Adder Circuit Let's Make an Adder Circuit Goal: = z for 4-bit integers. c Goal: = z for 4-bit integers. c 3 c = c 2 c 3 2 3 2 Step 2. (first attempt)! Build truth table. 3 2 Step 2. (do one bit at a time)! Build truth table for carr bit. 3 2! Wh is this a bad idea? z 3 z 2 z z! Build truth table for summand bit. z 3 z 2 z z 28-bit adder: 2 256 rows > # electrons in universe! c. 3 2 4-Bit Adder Truth Table 3 2 z 3 z 2 z z 2 8 = 52 rows! Carr Bit i i c i c i Summand Bit i i c i z i 2 22 Let's Make an Adder Circuit Let's Make an Adder Circuit Goal: = z for 4-bit integers. c 3 c = c 2 c Goal: = z for 4-bit integers. 3 2 Step 3.! Derive (simplified) Boolean epression. 3 2 Step 4.! Transform Boolean epression into circuit. z 3 z 2 z z! Chain together -bit adders. Carr Bit Summand Bit i i c i c i MAJ i i c i z i ODD 23 24
Let's Make an Adder Circuit Subtractor Goal: = z for 4-bit integers. Step 4.! Transform Boolean epression into circuit.! Chain together -bit adders. Subtractor circuit: z = -.! One approach: design like adder circuit.! Better idea: reuse adder circuit. 2's complement: to negate an integer, flip bits, then add 3 2 - - 3 2 carr z 3 z 2 z z 4-Bit Subtractor Interface 4-Bit Subtractor Implementation 25 26 Arithmetic Logic Unit: Interface Arithmetic Logic Unit: Implementation ALU Interface.! Add, subtract, bitwise and, bitwise or, shift left, shift right, cop.! Associate 3-bit integer with 5 primar ALU operations. ALU performs operations in parallel control wires select which result ALU outputs Input Input 2 6 6 ~ carr in op 2, - & ^ <<, >> input 2 Input Input 2 6 6 shift direction ALU subtract 3 ALU select 6 27 op 2, - & ^ <<, >> input 2 subtract & ^^ << >> shift direction MUX 3 ALU control 6 28
Summar Lessons for software design appl to hardware design!! Interface describes behavior of circuit.! Implementation gives details of how to build it. Laers of abstraction appl with a vengeance!! On/off.! Controlled switch (transistor).! Gates (AND, OR, NOT).! Boolean circuit (MAJ, ODD).! Adder.!.! Arithmetic logic unit.!.! TOY machine. 29