<<

Today’s Lecture

• No Recitation Friday • Projects (groups of 2 or 3) Outline Basics of Design: • Building the building blocks… , Logic Gates • Logic Design  Truth tables, Boolean functions, Gates and Circuits

Computer Science 104 Reading Appendix B

© Alvin R. Lebeck CPS 104 2

The Big Picture What We’ve Done, Where We’re Going

• The Five Classic Components of a

Application Top Down Operating Software Processor/CPU System Input Compiler Firmware Interface Between Control HW and SW Instruction Memory CPU Memory I/O system Architecture , Digital Design Memory, I/O Datapath Output Circuit Design Hardware

Bottom UP to CPU

© Alvin R. Lebeck CPS 104 3 © Alvin R. Lebeck CPS 104 4

Digital Design Boolean Algebra

• Logic Design, Switching Circuits, Digital Logic • Boolean functions have that take two Recall: Everything is built from transistors values ({T,F} or {1,0}) and they return a single or a set of ({T,F} or {1,0}) value(s). • A transistor is a switch • Boolean functions can always be represented by a • It is either on or off table called a “ ” • On or off can represent True or False • Example: F: {0,1} 3 -> {0,1} 2 Given a bunch of bits (0 or 1)… a b c f 1f2 • Is this instruction a lw or a beq? 0 0 0 0 1 • What register do I read? 0 0 1 1 1 0 1 0 1 0 • How do I add two numbers? 0 1 1 0 0 • Need a method to reason about complex expressions 1 0 0 1 0 1 1 0 0 1 1 1 1 1 1

© Alvin R. Lebeck CPS 104 5 © Alvin R. Lebeck CPS 104 6 Boolean Functions Boolean Functions and Expressions

• Example Boolean Functions: NOT, AND, OR, XOR, . . . • Boolean algebra notation : Use * for AND, + for OR, ~ for NOT. a NOT(a) a b AND(a,b) a b OR(a,b)  NOT is also written as A’ and A 0 1 0 0 0 0 0 0 • Using the above notation we can write Boolean 1 0 0 1 0 0 1 1 expressions for functions 1 0 0 1 0 1 1 1 1 1 1 1 F(A, B, C) = (A * B) + (~A * C)

a b XOR(a,b) a b XNOR(a,b) a b NOR(a,b) 0 0 0 0 0 1 0 0 1 • We can evaluate the Boolean expression with all 0 1 1 0 1 0 0 1 0 possible values to construct a truth table. 1 0 1 1 0 0 1 0 0 1 1 0 1 1 1 1 1 0 • What is truth table for F?

© Alvin R. Lebeck CPS 104 7 © Alvin R. Lebeck CPS 104 8

Boolean Simplification Boolean Function Simplification

• Boolean expressions can be simplified by using the following rules (bitwise logical):  A*A = A a b c f 1f2  A* 0 = 0 0 0 0 0 1 f1 = ~a *~b *c + ~a *b*c + a *~b *c + a *b*c  A*1 = A 0 0 1 1 1  A*~A = 0 0 1 0 0 0 0 1 1 1 0 f2 = ~a*~b*~c + ~a*~b*c + a*b*~c + a*b*c  A+A = A 1 0 0 0 0  A+0 = A 1 0 1 1 0  A+1 = 1 1 1 0 0 1  A+~A = 1 1 1 1 1 1 Simplify these functions...

 A*B = B*A  A*(B+C) = (B+C)*A = A*B + A*C

© Alvin R. Lebeck CPS 104 10 © Alvin R. Lebeck CPS 104 11

Boolean Functions and Expressions Boolean Functions and Expressions

• The Fundamental of Boolean Algebra : • Example-2: Every Boolean function can be written in as an OR of ANDs ( Sum-of products ) of a b c f 1f2 it’s arguments or their complements. 0 0 0 0 1 f1 = ~a *~b *c + ~a *b*~c + a *~b *~c + a *b*c 0 0 1 1 1 “Proof:” Write the truth table, construct sum-of- 0 1 0 1 0 product from the table. 0 1 1 0 0 f2 = ~a*~b*~c + ~a*~b*c + a*b*~c + a*b*c 1 0 0 1 0 1 1 0 0 1 a b XNOR(a,b) 1 1 1 1 1 0 0 1 0 1 0 XNOR = (~a * ~b) + (a * b) 1 0 0 1 1 1

© Alvin R. Lebeck CPS 104 13 © Alvin R. Lebeck CPS 104 14 Applying the Theory Boolean Gates

• Lots of good theory • Gates are electronic devices that implement simple • Can reason about complex boolean expressions Boolean functions • Now we have to make it real… Examples

a a AND(a,b) OR(a,b) a NOT(a) b b

a XOR(a,b) a NAND(a,b) b b

a NOR(a,b) a XNOR(a,b) b b

© Alvin R. Lebeck CPS 104 15 © Alvin R. Lebeck CPS 104 16

Reality Check Boolean Functions, Gates and Circuits

• Basic 1 or 2 Input Boolean Gate 1- 4 Transistors • Circuits are made from a network of gates. (function compositions). Pentium III a b XOR(a,b) a 0 0 0 • Processor Core 9.5 Million Transistors XOR(a,b) F = ~a*b + ~b*a b 0 1 1 • Total: 28 Million Transistors 1 0 1 Pentium 4 1 1 0 • Total: 42 Million Transistors a Core2 Duo (two processors) • Total: 290 Million Transistors F b Core2 Duo Extreme (4 processors, 8MB cache) • Total: 590 Million Transistors

© Alvin R. Lebeck CPS 104 17 © Alvin R. Lebeck CPS 104 18

Digital Design Examples Design Example

Input: 2 bits representing an unsigned number (n) • Consider machine with 4 registers 2 Output: n as 4-bit unsigned binary number • Given 2-bit input (register specifier, I 1, I 0)

• Want one of 4 output bits (O 3-O0) to be 1  E.g., allows a single register to be accessed Input: 2 bits representing an unsigned number (n) • What is the circuit for this? Output: 3-n as unsigned binary number

© Alvin R. Lebeck CPS 104 19 © Alvin R. Lebeck CPS 104 20 More Design Examples Parity Example

• X is a 3-bit quantity • The parity code of a binary word counts the number 1. Write a logic function that is true if and only if X contains at of ones in a word. If there are an even number of least two 1s. ones the parity code is 0, if there are an odd number 2. Implement the logic function from problem 1. using only AND, of ones the parity code is 1. For example, the parity OR and NOT gates. (Note there are no constraints on the of 0101 is 0, and the parity of 1101 is 1. number of gate inputs.) By implement, I mean draw the circuit diagram. • Construct the truth table for a function that computes the parity of a four-bit word . Implement 3. Write a logic function that is true if and only if X, when this function using AND, OR and NOT gates. (Note interpreted as an unsigned binary number, is greater than the there are no constraints on the number of gate number 4. inputs.) 4. Implement the logic function from problem 3. using only AND, OR and NOT gates. (Note there are no constraints on the number of gate inputs.)

© Alvin R. Lebeck CPS 104 21 © Alvin R. Lebeck CPS 104 22

Circuit Example: Decoder Circuit Example: 2x1 MUX

Q3 Multiplexor (MUX) selects from one of many inputs

I1 I0 Q0 Q1 Q2 Q3 a 1 y Q2 0 0 1 0 0 0 MUX(A, B, S) = (A * S) + (B * ~S) b 0 0 1 0 1 0 0 Q s 1 1 0 0 0 1 0

1 1 0 0 0 1 B Q0 Gate 1 Y = (A * S) + (B * ~S) Gate 3

A Gate 2

S

I1 I0

© Alvin R. Lebeck CPS 104 23 © Alvin R. Lebeck CPS 104 24

Example 4x1 MUX Arithmetic and Logical Operations in ISA

• What operations are there? a 1 • How do we implement them? 3 b 0 a  Consider a 1-bit Adder 1 y 2 0 b y c 1 c 1 d 0 d 0

s0 s1 2

S

© Alvin R. Lebeck CPS 104 25 © Alvin R. Lebeck CPS 104 26 Summary

• Boolean Algebra & functions • Logic gates (AND, OR, NOT, etc) • Multiplexors Reading • Appendix B

© Alvin R. Lebeck CPS 104 27