1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

65
1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B

Transcript of 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

Page 1: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

1

CS/COE0447

Computer Organization & Assembly Language

Logic DesignAppendix B

Page 2: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

2

Outline

• Example to begin: let’s implement a MUX!

• Gates, Truth Tables, and Logic Equations

• Combinatorial Logic

• Constructing an ALU

• Memory Elements: Flip-flops, Latches, and Registers (if there is time)

Page 3: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

3

Logic Gates

Y=A&B

Y=A|B

Y=~(A&B)

Y=~(A|B)

2-input AND

2-input OR

2-input NAND

2-input NORA

B

A

A

A

B

B

BY

Y

Y

Y

Page 4: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

4

MultiplexorIf S then C=B else C = A

A

C

B

S

0

1

How many bits is S?

1, since it is choosing between 2 values

Let’s see how to implement a 2-input MUX using gates.

Hint: the answer uses AND gates, an OR gate, and one INVERTER Answer in lecture; Figure B.3.2 shows the answer as well.

Page 5: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

5

Computers and Logic

• Digital electronics operate with only two voltage levels of interest: high and low voltage. – All other voltage levels are temporary and occur while

transitioning between values

• We’ll talk about them as signals that are – Logically true; 1; asserted– Logically false; 0, deasserted

• 0 and 1 are complements and inverses of each other

Page 6: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

6

Combinational vs. Sequential Logic

• Combinational logic– A function whose outputs depend only on the

current input

• Sequential logic– Memory elements, i.e., state elements– Outputs are dependent on current input and

current state– Next state is also dependent on current input

and current state

Page 7: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

7

Combinational Logic

inputs outputs… …

Page 8: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

8

Sequential Logic

inputs outputs… …clock

currentstate

nextstate

Page 9: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

9

• The next set of topics [until the sequential logic picture we just saw pops up again] will only be about combinatorial logic

Page 10: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

10

Functions Implemented Using Gates

inputs outputs… …?

Combinatorial logic blocks implement logical functions, mapping inputs to outputs

Page 11: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

11

Describing a Function

• OutputA = F(Input0, Input1, …, InputN-1)

• OutputB = F’(Input0, Input1, …, InputN-1)

• OutputC = F’’(Input0, Input1, …, InputN-1)

• [each output is its own function of the inputs]

• Methods– Truth table (since combinatorial logic has no me

mory, it can be completely specified by a truth table)

– …[in a moment]

Page 12: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

12

Truth Table

Input Output

A B Cin S Cout

0 0 0 0 0

0 0 1 1 0

0 1 0 1 0

0 1 1 0 1

1 0 0 1 0

1 0 1 0 1

1 1 0 0 1

1 1 1 1 1

Page 13: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

13

Truth Tables

• In a truth table, there is one row for every possible combination of values of the inputs

• Specifically, if there are N inputs, the possible combinations are the binary numbers 0 through 2EN - 1. For example:– 3 bits (0-7): 000 through 111 – 4 bits (0-15): 0000 through 1111– 5 bits (0-31): 00000 through 11111

• While we could always use a truth table, they quickly grow in size and become hard to understand and work with

• Boolean logic equations are more succinct

Page 14: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

14

Describing a Function

• OutputA = F(Input0, Input1, …, InputN-1)

• OutputB = F’(Input0, Input1, …, InputN-1)

• OutputC = F’’(Input0, Input1, …, InputN-1)

• [each output is its own function of the inputs]

• Methods– Truth table – Boolean logic equations

Page 15: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

15

Truth Table and Equations

• S = A’B’Cin+A’BCin’+AB’Cin’+ABCin

• Cout = A’BCin+AB’Cin+ABCin’+ABCin

Input Output

A B Cin S Cout

0 0 0 0 0

0 0 1 1 0

0 1 0 1 0

0 1 1 0 1

1 0 0 1 0

1 0 1 0 1

1 1 0 0 1

1 1 1 1 1

Each output has its own…? Column in the truth table

And its own Boolean equation

Page 16: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

16

Truth Tables and Equations

• All functions specified by truth tables can also be specified by Boolean formulas [and vice versa]

• So, let’s look more closely at Boolean algebra

Page 17: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

17

Boolean Algebra

• Boole, George (1815~1864): mathematician and philosopher; inventor of Boolean Algebra, the basis of all computer arithmetic

• Binary values: 0, 1• Two binary operations: AND (/), OR ()

– AND is also called the logical product since its result is 1 only if both operands are 1

– OR is also called the logical sum since its result is 1 if either operand is 1

• One unary operation: NOT (~)

Page 18: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

18

Laws of Boolean Algebra • Identity, Zero, and One laws

– aa = a+a = a– a1 =a; a+0 = a [“copy” operations]– a0 =0; a+1 = 1 [deassert by ANDing with 0; assert by ORing with 1]

• Inverse – aa = 0; a+a = 1

• Commutative– ab = ba– a+b = b+a

• Associative– a(bc) = (ab)c– a+(b+c) = (a+b)+c

• Distributive– a(b+c) = ab + ac – a+(bc) = (a+b)(a+c)

Page 19: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

19

Laws of Boolean Algebra

• De Morgan’s laws– ~(a+b) = ~a~b– ~(ab) = ~a+~b

• More…– a+(ab) = a– a(a+b) = a– ~~a=a

• You’ll see this again in CS441 and CS1502

Page 20: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

20

Examples

• To get used to Boolean equations

• To see the relationships among Truth Tables, Boolean Equations, and hardware implementations in gates

• To see that a “sum of products” formula can always be derived from a truth table

• To see that equations can often be simplified

Page 21: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

21

Example equation

• E = (A’ B C) + (A B’ C) + (A B C’) • What is the value of the equation if A = 1, B = 0

and C = 0?• E = (1’ 0 0) + (1 0’ 0) + (1 0 0’)• E = (0 0 0) + (1 1 0) + (1 0 1) = 0• What is the value of the equation if A = 0, B = 1,

and C = 1?• E = (0’ 1 1) + (0 1’ 1) + (0 1 1’)• E = (1 1 1) + (0 0 1) + (0 1 0) = 1

Page 22: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

22

Truth Table for EA B C D E F

0 0 0 0 0 0

0 0 1 1 0 0

0 1 0 1 0 0

0 1 1 1 1 0

1 0 0 1 0 0

1 0 1 1 1 0

1 1 0 1 1 0

1 1 1 1 0 1

•You can read our equation for E right from the truth table:• E = (A’ B C) + (A B’ C) + (A B C’) •These are the three cases when E is 1. •Now, give a Boolean equation for F:

F = A B C

Page 23: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

23

Give a Boolean Equation for DA B C D E F

0 0 0 0 0 0

0 0 1 1 0 0

0 1 0 1 0 0

0 1 1 1 1 0

1 0 0 1 0 0

1 0 1 1 1 0

1 1 0 1 1 0

1 1 1 1 0 1

D = (A’ B’ C) + (A’ B C’) + (A’ B C) + (A B’ C’) + (A B’ C) + (A B C’) + (A B C)

There are many logically equivalent equations (in general)

D = (A’ B’ C’)’ [D is true in all cases except A=0 B=0 C=0.] Apply DeMorgan’s law:

D = A’’ + B’’ + C’’ = A + B + C

Page 24: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

24

Example: boolean equation of a circuitFirst add the boolean equations at the output for each AND gate

A

BY

C

A•B

B•C

Page 25: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

25

Example:

Next add the Boolean equations at the output for the OR gate

The Boolean equation for the complete logic circuit is:

Y = (A•B)+(B•C)

B•C

A

B Y

C

A•B (A•B) + (B•C)

Page 26: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

26

Example: Truth Table

Y = (A•B)+(B•C)

A B C Y

0 0 0 0

0 0 1 0

0 1 0 0

0 1 1 1

1 0 0 0

1 0 1 0

1 1 0 1

1 1 1 1

Reading an equation from the Table:Y = (A’ B C) + (A B C’) + (A B C)The equations are logically equivalent: one way to see this is to considereach row in the truth table. If the two equations have the same outputs foreach input, then they are logically equivalent.

Page 27: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

27

Example: MUXA

B

S

C

(A S’)

(B S)

(A S’) + (B S)

A B S C

0 0 0 0

0 0 1 0

0 1 0 0

0 1 1 1

1 0 0 1

1 0 1 0

1 1 0 1

1 1 1 1

Equation read from the Table: C = (A’ B S) + (A B’ S’) + (A B S’) + (A B S)

Again, the two formulas are equivalent [next slide]

If the equation below were implemented directly:four (3-input) AND gates and one (4-input) ORgate would be needed

Page 28: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

28

Example: MUXC = (A S’) + (B S)

A B S C

0 0 0 0

0 0 1 0

0 1 0 0

0 1 1 1

1 0 0 1

1 0 1 0

1 1 0 1

1 1 1 1

C = (A’ B S) + (A B’ S’) + (A B S’) + (A B S)

You can see theyare equivalent by comparing valuesfor each row

BS

AS’If B ==0: (AS’) + 0If B == 1: 0 + (AS’)So, this is the same as AS’

Methods e.g. using Karnaugh Mapsperform such simplificationsautomatically [we won’t covermore of this in this class, unlesswe have extra time]

Page 29: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

29

Expressive Power

• Any Boolean algebra function can be constructed using AND gates, OR gates, and Inverters– [For your interest: NAND and NOR are both universal: any logic

function can be built with just that one gate type]

• There are “canonical forms” for Boolean functions: all equations can be expressed in these forms

• This made it possible to create translation programs that, given a logic equation or truth table as input, can automatically design a circuit that implements it

Page 30: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

30

Outline

• Example to begin: let’s implement a MUX!

• Gates, Truth Tables, and Logic Equations

• Combinatorial Logic

• Constructing an ALU

• Memory Elements: Flip-flops, Latches, and Registers (if there is time)

Page 31: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

31

Since we were talking about MUXs…

• How are larger MUXs implemented– Wider inputs than 1 bit– More choices

Page 32: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

32

A 32-bit wide 2-to-1 Multiplexor

Choosing between 232-bit wide busesBus: collection of data linestreated as a single value.E.g., MUX controlled byMemtoReg.

1-bit input to to all 32 MUXs

Each MUX is thesame; just like theone we saw earlier

Page 33: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

33

Use a Decoder to build a MUX with more choices

    Decoder n bit input value and 2^n outputs (Fig B.3, pB8)

 

I1 I2 O3 O2 O1 O0

0 0 0 0 0 1

0 1 0 0 1 0

1 0 0 1 0 0

1 1 1 0 0 0

This is a 2-to-4 decoderPage B-9 shows the truth table for a 3-to-8 decoder

Page 34: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

34

Decoder: implementation with gates

   Decoder n bit input value and 2^n outputs

A = X • Y B = X • Y C = X • Y D = X • Y

X Y A B C D

0 0 0 0 0 1

0 1 0 0 1 0

1 0 0 1 0 0

1 1 1 0 0 0

D

C

B

A

C

XY

Page 35: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

35

N input MUX using a decoder

• Example in lecture

Page 36: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

36

Implementing Combinatorial Logic

• PLA (Programming Logic Array)– A direct implementation of sum of products for

m pla.html (thanks to: www.cs.umd.edu/class/spring2003/cmsc311/Notes/Comb/pla.html)

• ROM (Read Only Memory)– Interpret the truth table as fixed values stored

in memory

• Using logic gate chips (74LS…)

Page 37: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

37

74LS Series

• Chips contain several logic gates

081

4

9

12

2

5

10

13

3

6

8

11

SN 74LS08 Quad 2-input AND gate

321

4

9

12

2

5

10

13

3

6

8

11

SN 74LS32 Quad 2-input OR gate

SN 74LS04 Hex inverter gate

04

1

3

5

9

11

13

2

4

6

8

10

12

Page 38: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

38

Fig 5.28 (added for reference)

Page 39: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

39

ALU Symbol

• Note that it’s combinational logic

Page 40: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

40

Building a 1-bit ALU

• ALU = Arithmetic Logic Unit

Page 41: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

41

Building a 32-bit ALU

Page 42: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

42

Implementing “SUB”

Page 43: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

43

Implementing “NAND”/”NOR”

Page 44: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

44

Implementing “SLT”

Page 45: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

45

Implementing “SLT”, cont’d

Page 46: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

46

Supporting “BEQ”/”BNE”

• Need a “zero-detector”

Page 47: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

47

ALU Symbol

• Note that it’s a combinational logic

Page 48: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

48

Sequential Logic

inputs outputs… …clock

currentstate

nextstate

Page 49: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

49

RS Latch

• Note that there are feedbacks!

Page 50: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

50

RS Latch, cont’d

• When R=0, S=1

0

1 0

10

1

Page 51: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

51

RS Latch, cont’d

• When R=1, S=0

1

0 1

01

0

Page 52: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

52

RS Latch, cont’d

• When R=0, S=0, and Q was 0

0

0 1

01

0

Page 53: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

53

RS Latch, cont’d

• When R=0, S=0, and Q was 1

0

0 0

10

1

Page 54: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

54

RS Latch, cont’d

• What happens if R=S=1?

1

1

Page 55: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

55

D Latch

• Note that we have an R-S latch as a back-end

Page 56: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

56

D Latch, cont’d

• Note that S, R inputs always get inverted input of D when C=1

• When C=0, S=R=0, remembering the previous value

S

R

Page 57: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

57

D Latch, cont’d

S

R C D Q(t)

0 0 Q(t-1)

0 1 Q(t-1)

1 0 0

1 1 1

Page 58: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

58

D Latch, cont’d

D

C

Q

Q’

D Latch

Page 59: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

59

D Flip-Flop (D-FF)

• Two D latches are cascaded, with opposite clock

Page 60: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

60

D Flip-Flop, cont’d

D

C

Q

Q’

D-FF

Page 61: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

61

Register File Implementation we’ll return to this in appendix B

Page 62: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

62

Reg. File Impl., cont’d we’ll return to this in appendix B

1

0x11223344

0x11223344

1

0

0

0

11

1

0

0

0

Page 63: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

63

To Summarize…

• In digital logic, transistors are used as simple switches

• Logic gate is an abstraction of multiple transistor network

• A combinational logic block has inputs and outputs that depend on the current inputs

• A sequential logic block is composed of some combinational logic and memory that keeps the current state

Page 64: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

64

To Summarize…, cont’d

• Boolean algebra provides theory for digital logic

• Combinational logic can be implemented using PLA (and many other methods)

• An ALU for MIPS architecture has been built!

Page 65: 1 CS/COE0447 Computer Organization & Assembly Language Logic Design Appendix B.

65

To Summarize…, cont’d

• Flip-flops were used as a memory element

• An FSM can be implemented using FFs and some combinational logic