<<

Architecture

Lecture 10: Combinational Circuits Previous two lectures.

! TOY machine.

Next two lectures.

! Digital circuits.

Culminating lecture.

George Boole (1815 – 1864) Claude Shannon (1916 – 2001) ! Putting it all together and building a TOY machine.

COS126: General Computer Science • http://www.cs.Princeton.EDU/~cos126 2

Digital Circuits Wires

What is a digital system? Wires.

! Digital: signals are 0 or 1. ! Propagate logical values from place to place.

! Analog: signals vary continuously. ! Signals "flow" from left to right. – A drawing convention, sometimes violated Why digital systems? – Actually: flow from producer to consumer(s) of signal

! Accuracy and reliability.

! Staggeringly fast and cheap. 0 0

Basic abstractions. 1 1 ! On, off.

! Switch that can turn something on or off. 1 1 Digital circuits and you.

! Computer . Input Output

! Antilock brakes.

! Cell phones.

3 4 Logic Gates Multiway AND Gates

Logical gates. AND(x0, x1, x2, x3, x4, x5, x6, x7).

! Fundamental building blocks. ! 1 if all inputs are 1.

! 0 otherwise. x x x x' xy x + y y y

0 0 0 0 0 0

0 0 0 1 0 1 1 1

1 1 1 0 0 1 0 0

1 1 1 1 1 1

NOT AND OR

5 6

Multiway OR Gates

OR(x0, x1, x2, x3, x4, x5, x6, x7). History.

! 1 if at least one input is 1. ! Developed by Boole to solve mathematical logic problems (1847).

! 0 otherwise. ! Shannon first applied to digital circuits (1937).

Basics.

! Boolean variable: value is 0 or 1.

! : function whose inputs and outputs are 0, 1.

Relationship to circuits.

! Boolean variables: signals.

! Boolean functions: circuits.

7 8 Truth Table Truth Table for Functions of 2 Variables

Truth table. Truth table.

! Systematic method to describe Boolean function. ! 16 Boolean functions of 2 variables.

! One row for each possible input combination. – every 4-bit value represents one N ! N inputs ! 2 rows.

Truth Table for All Boolean Functions of 2 Variables 0 x y ZERO AND x y XOR OR AND Truth Table 0 0 0 0 0 0 0 0 0 0 0 0 x y AND(x, y) 0 1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 0 1 1 0 0 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 0 0 0 0 Truth Table for All Boolean Functions of 2 Variables 1 1 1 1 x y NOR EQ y' x' NAND ONE 1 1 0 0 1 1 1 1 1 1 1 1 0 1 0 0 0 0 1 1 1 1 AND 1 0 0 0 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 9 10

Truth Table for Functions of 3 Variables Universality of AND, OR, NOT

Truth table. Any Boolean function can be expressed using AND, OR, NOT.

! 16 Boolean functions of 2 variables. ! "Universal."

– every 4-bit value represents one ! XOR(x,y) = xy' + x'y

! 256 Boolean functions of 3 variables. – every 8-bit value represents one Expressing XOR Using AND, OR, NOT ! 2^(2^N) Boolean functions of N variables! x y x' y' x'y xy' x'y + xy' XOR 0 0 1 1 0 0 0 0 Some Functions of 3 Variables 0 1 1 0 1 0 1 1 x y z AND OR MAJ ODD 1 0 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 Notation Meaning 0 1 1 0 1 1 0 x' NOT x x y x AND y 1 0 0 0 1 0 1 x + y x OR y 1 0 1 0 1 1 0 1 1 0 0 1 1 0 Exercise: {AND, NOT}, {OR, NOT}, {NAND}, {AND, XOR} are universal. 1 1 1 1 1 1 1

11 12 Sum-of-Products Translate Boolean Formula to Boolean Circuit

Any Boolean function can be expressed using AND, OR, NOT. Use sum-of-products form.

! Sum-of-products is systematic procedure. ! XOR(x, y) = xy' + x'y. – form AND term for each 1 in truth table of Boolean function – OR terms together

Expressing MAJ Using Sum-of-Products x y z MAJ x'yz xy'z xyz' xyz x'yz + xy'z + xyz' + xyz 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 1 1 0 1 0 0 1 1 1 0 1 0 0 1 0 1 1 1 1 1 0 0 0 1 1

13 14

Translate Boolean Formula to Boolean Circuit Simplification Using Boolean Algebra

Use sum-of-products form. Many possible circuits for each Boolean function.

! MAJ(x, y, z) = x'yz + xy'z + xyz' + xyz. ! Sum-of-products not necessarily optimal in: – number of gates (space) – depth of circuit (time)

! MAJ(x, y, z) = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

size = 8, depth = 3 size = 4, depth = 2

15 16 Expressing a Boolean Function Using AND, OR, NOT ODD Parity Circuit

Ingredients. ODD(x, y, z).

! AND gates. ! 1 if odd number of inputs are 1.

! OR gates. ! 0 otherwise.

! NOT gates.

! Wire.

Expressing ODD Using Sum-of-Products Instructions. x y z ODD x'y'z x'yz' xy'z' xyz x'y'z + x'yz' + xy'z' + xyz 0 0 0 0 0 0 0 0 0 ! Step 1: represent input and output signals with Boolean variables. 0 0 1 1 1 0 0 0 1 ! Step 2: construct truth table to carry out computation. 0 1 0 1 0 1 0 0 1 ! Step 3: derive (simplified) Boolean expression using sum-of products. 0 1 1 0 0 0 0 0 0 ! Step 4: transform Boolean expression into circuit. 1 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 1 0 0 0 1 1

17 18

ODD Parity Circuit Let's Make an Circuit

ODD(x, y, z). Goal: x + y = z for 4-bit integers. 1 1 1 0 ! 1 if odd number of inputs are 1. ! We build 4-bit adder: 9 inputs, 4 outputs. 2 4 8 7 ! 0 otherwise. ! Same idea scales to 128-bit adder. + 3 5 7 9 ! Key computer component. 6 0 6 6

Step 1.

! Represent input and output in binary. 1 1 0 0 0 0 1 0 x3 x2 + 0 1 1 1 x 1 1 0 0 1 x 0 + z2 z1 x3 x2 x1 x0 z0 y3 + y3 y2 y1 y0 y2 c 0 y1 z3 z2 z1 z0 y0

19 20 Let's Make an Adder Circuit Let's Make an Adder Circuit

c c c c = 0 Goal: x + y = z for 4-bit integers. c0 Goal: x + y = z for 4-bit integers. 3 2 1 0

x3 x2 x1 x0 x3 x2 x1 x0 Step 2. (first attempt) Step 2. (do one bit at a time) + y3 y2 y1 y0 + y3 y2 y1 y0 ! Build truth table. ! Build truth table for carry bit. z3 z2 z1 z0 z3 z2 z1 z0 ! Why is this a bad idea? ! Build truth table for summand bit. – 128-bit adder: 2256+1 rows > # electrons in universe!

Carry Bit Summand Bit 4-Bit Adder Truth Table xi yi ci ci+1 xi yi ci zi c x x x x y y y y z z z z 0 3 2 1 0 3 2 1 0 3 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 1 1 1 0 0 0 1 0 0 1 28+1 = 512 rows! 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 0 1 0 1 1 1 0 1 1 1 0 0 ...... 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 21 22

Let's Make an Adder Circuit Let's Make an Adder Circuit

Goal: x + y = z for 4-bit integers. c3 c2 c1 c0 = 0 Goal: x + y = z for 4-bit integers.

x3 x2 x1 x0 Step 3. Step 4. + y3 y2 y1 y0 ! Derive (simplified) Boolean expression. ! Transform Boolean expression into circuit. z3 z2 z1 z0 ! Chain together 1-bit adders.

Carry Bit Summand Bit

xi yi ci ci+1 MAJ xi yi ci zi ODD 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 0 1 0 0 0 0 1 0 1 1 0 1 1 1 1 0 1 1 0 0 1 0 0 0 0 1 0 0 1 1 1 0 1 1 1 1 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1

23 24 Let's Make an Adder Circuit

Goal: x + y = z for 4-bit integers. Subtractor circuit: z = x - y.

! One approach: design like adder circuit.

Step 4. ! Better idea: reuse adder circuit.

! Transform Boolean expression into circuit. – 2's complement: to negate an integer, flip bits, then add 1

! Chain together 1-bit adders.

x3

x2

x1 z x0 3 z x 2 + z1 y z x - y 3 0 - y2 y rr y1 ca y y0 1

4-Bit Subtractor Interface 4-Bit Subtractor Implementation

25 26

Arithmetic Logic Unit: Interface : Implementation

ALU Interface. 16 Input 1 ! Add, subtract, bitwise and, bitwise xor, shift left, shift right, copy. 000 16 + ! Associate 3-bit integer with 5 primary ALU operations. Input 2 – ALU performs operations in parallel ~ carry in – control wires select which result ALU outputs

& 001 16 16 Input 1 op 2 1 0 MUX +, - 0 0 0 ALU ^ 010 & 0 0 1 16 ^ ^ 0 1 0

<<, >> 0 1 1 << 011 input 2 1 0 0 16 >> Input 2 3 op 2 1 0 +, - 0 0 0 100 3 ALU & 0 0 1 select ^ 0 1 0 shift subtract <<, >> 0 1 1 input 2 1 0 0 subtract shift direction ALU control direction 27 28 Summary

Lessons for software design apply to hardware design!

! Interface describes behavior of circuit.

! Implementation gives details of how to build it.

Layers of abstraction apply with a vengeance!

! On/off.

! Controlled switch (transistor).

! Gates (AND, OR, NOT).

! Boolean circuit (MAJ, ODD).

! Adder.

! . . .

! Arithmetic logic unit.

! . . .

! TOY machine.

29