unit 1: the model of the computer - david-abel.github.io · ‣ state machines! ... ‣ michael’s...

103
1 February 5th, 2016 Dave Abel Unit 1: The Model of the Computer

Upload: hanhan

Post on 06-Jun-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

1

February 5th, 2016

Dave Abel

Unit 1: The Model of the Computer

Today’s Takeaway

2

‣ Earlier this week: computers are doing logic with gates!

‣ Today: Memory, Logic, and input/output = Computer!

Outline for Today

3

‣ Review of Gates

- AND, OR, NOT, Composite Gates

- Domino Gates, XOR, Adding with Gates

‣ State Machines!

‣ Model of a Computer

4

Gates: NOT

1 0N

ot

0 1

P NOT(P)

1 0

0 1

Not

5

Gates: NOT

Not

1 0

Q: What is this, physically?

6

Gates: NOT

Not

1 0

Q: What is this, physically?

A: High voltage electrical pulses!

7

Gates: NOT

1 0

8

Gates: NOT

P NOT(P)

1 0

0 1

1 0

0 1

9

Gates: ANDP Q AND( P Q)

1 1 1 1 1

1 0 0 1 0

0 1 0 0 1

0 0 0 0 0

AND

1

1AND(P,Q) = 1

10

Gates: ORP Q OR( P Q)

1 1 1 1 1

1 0 1 1 0

0 1 1 0 1

0 0 0 0 0

OR

OR(P,Q) = 10

1

11

Gates

OR

P

Q

OR(P,Q)

AND

P

Q

AND(P,Q)

Not

P NOT(P)

12

Gates: Composition

OR(P,NOT(Q))

A: OR

POR(P,NOT(Q))

Not

Q NOT(Q)

P Q OR( P NOT( Q)

T T T T F T

T F T T T F

F T F F F T

F F T F T F

Domino Gates

13

P

Q

OR(P,Q)

14

Domino Gates

Could It Work?

15

‣ Michael’s domino OR gate: 24 dominoes

‣ The first pentium processor had 3.3 Mill transistors, or roughly 800k gates.

‣ So we need around 20 Mill dominoes

‣ World record for domino topple: 4.5 Mill

‣ Pentium: computes 60 Mill times a second

‣ Dominoes? Takes awhile to set up…

Two Different Notions of Speed

16

1. Electricity vs. Dominos falling over

2. Do we have the shortest computation for that problem?

Problem: Speed!

17

P NOT(NOT(P))=

Problem: Speed!

18

P NOT(NOT(P))

# of Gates: 0 2

Problem: Speed!

19

P NOT(NOT(NOT(NOT(P))))

# of Gates: 0 4

Problem: Speed!

20

P NOT(NOT(NOT(NOT(NOT(P)))))

# of Gates: 0 6

Problem: Speed!

21

P NOT(NOT(NOT(NOT(NOT(P)))))…….

# of Gates: 0 6024

Problem: Speed!

22

P NOT(NOT(NOT(NOT(NOT(P)))))…….

# of Gates: 0 6024

Think about that many domino gates…

Problem: Speed!

23

P NOT(NOT(NOT(NOT(NOT(P)))))…….

# of Gates: 0 6024

Identical logical formulas, dramatically different speed of computation!

Think about that many domino gates…

24

One Last Gate… XORP Q XOR( P Q)

1 1 0 1 1

1 0 1 1 0

0 1 1 0 1

0 0 0 0 0

XOR

25

One Last Gate… XORP Q XOR( P Q)

1 1 0 1 1

1 0 1 1 0

0 1 1 0 1

0 0 0 0 0

26

One Last Gate… XORP Q XOR( P Q)

1 1 0 1 1

1 0 1 1 0

0 1 1 0 1

0 0 0 0 0

XOR

27

Arithmetic and LogicWe know how to do addition, subtraction, and

multiplication in binary…

But we’ve claimed that computers used AND, OR, NOT gates at their core to do everything…

28

Arithmetic and LogicWe know how to do addition, subtraction, and

multiplication in binary…

But we’ve claimed that computers used AND, OR, NOT gates at their core to do everything…

Q: Can we represent addition with logical gates?

29

Arithmetic and Gates

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

Q: Can we represent addition with logical gates?

30

Arithmetic and Gates

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

XOR

Hint: you’ll need these:

AND

Q: Can we represent addition with logical gates?

31

Arithmetic and Gates

XOR

AND

topNumber

bottomNumbertwo’s digit

one’s digit

A:

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

32

Arithmetic and Gates

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

XOR

AND

0

0two’s digit

one’s digit

A:

33

Arithmetic and Gates

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

XOR

AND

0

0two’s digit

one’s digit

A:

34

Arithmetic and Gates

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

XOR

AND

0

0two’s digit

0

A:

35

Arithmetic and Gates

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

XOR

AND

0

0two’s digit

0

A:

36

Arithmetic and Gates

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

XOR

AND

0

00

0

A:

37

Arithmetic and Gates

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

XOR

AND

1

1two’s digit

one’s digit

A:

38

Arithmetic and Gates

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

XOR

AND

1

1two’s digit

one’s digit

A:

39

Arithmetic and Gates

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

XOR

AND

1

1two’s digit

0

A:

40

Arithmetic and Gates

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

XOR

AND

1

1two’s digit

0

A:

41

Arithmetic and Gates

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

XOR

AND

1

11

0

A:

42

Arithmetic and Gates

0+ 00 0

1+ 00 1

0+ 10 1

1+ 11 0

1

XOR

AND

1

11

0

A:

Binary Adder

44

Truth Table to Formula

Idea: with a certain set of logical functions, we can represent all

possible logical formulas!

45

Truth Table to Gate

Idea: with a certain set of logical functions gates, we can represent all

possible logical formulas!

Abstraction:

46

OR

P

Q

OR(P,Q)

AND

P

Q

AND(P,Q)

Not

P NOT(P)

all possible logical

formulas!

Abstraction:

47

Low level programs

Abstraction:

48

Low level programs

High level programs

Abstraction:

49

Low level programs

High level programs

Your ideas!=

State Machines

50

State Machines: Example

51

Suppose we want a blinking christmas light:

State Machines: Example

52

Suppose we want a blinking christmas light:

O = was the light on a second ago?N = is the light on now?

State Machines: Example

53

oldLight = was the light on a second ago?

Suppose we want a blinking christmas light:

newLight = is the light on now?

State Machines: Example

54

oldLight = was the light on a second ago?

Suppose we want a blinking christmas light:

newLight = is the light on now?Q: How can we write the value of newLight in

terms of oldLight?

State Machines: Example

55

oldLight = was the light on a second ago?

Suppose we want a blinking christmas light:

newLight = is the light on now?

A: newLight = NOT(oldLight)

State Machines: Example

56

Suppose we want a blinking christmas light:

A: newLight = NOT(oldLight)

Not

newLightoldLight

…1 second delay

State Machines: Example

57

Suppose we want a blinking christmas light:

A: newLight = NOT(oldLight)

Not

newLightoldLight

…1 second delay

State Machines: Example

58

Suppose we want a blinking christmas light:

A: newLight = NOT(oldLight)

Not

newLightoldLight

…1 second delay

State Machines: Example

59

Suppose we want a blinking christmas light:

A: newLight = NOT(oldLight)

Not

newLightoldLight

…1 second delay

State Machines: Example

60

Suppose we want a blinking christmas light:

A: newLight = NOT(oldLight)

Not

newLightoldLight

…1 second delay

State Machines: Example

61

Suppose we want a blinking christmas light:

A: newLight = NOT(oldLight)

Not

newLightoldLight

…1 second delay

State Machines: Example

62

Suppose we want a blinking christmas light:

ONSTATE

OFFSTATE

A More Complicated Example: Sliding Doors

63

A More Complicated Example: Sliding Doors

64

isPersonLeft isPersonRight

A More Complicated Example: Sliding Doors

65

isPersonLeft isPersonRight

A More Complicated Example: Sliding Doors

66

isPersonRightisPersonLeft

A More Complicated Example: Sliding Doors

67

isPersonRightisPersonLeft

A More Complicated Example: Sliding Doors

68

isPersonRightisPersonLeft

OR doorOpen

DOORCLOSED

DOOROPEN

A More Complicated Example: Sliding Doors

69

DOORCLOSED

DOOROPEN

A More Complicated Example: Sliding Doors

70

DOORCLOSED

DOOROPEN

A More Complicated Example: Sliding Doors

71

OR(left,right)

DOORCLOSED

DOOROPEN

A More Complicated Example: Sliding Doors

72

OR(left,right)

NOT(OR(left,right))

DOORCLOSED

DOOROPEN

A More Complicated Example: Sliding Doors

73

OR(left,right)

NOT(OR(left,right))

left = 0right = 0Memory:

readread

DOORCLOSED

DOOROPEN

A More Complicated Example: Sliding Doors

74

Q: How else can we write this with logic?

NOT(OR(left,right))

OR(left,right)

DOORCLOSED

DOOROPEN

A More Complicated Example: Sliding Doors

75

Q: How else can we write this with logic?A: AND(NOT(left),NOT(right))

NOT(OR(left,right))

OR(left,right)

Side Note: DeMorgan’s Law

76

NOT(OR(left,right))

AND(NOT(left),NOT(right))

=

Side Note: DeMorgan’s Law

77

P Q AND( NOT(P) NOT(Q))

1 1 0 0 01 0 0 0 10 1 0 1 00 0 1 1 1

P Q NOT( OR(P,Q))

1 1 0 11 0 0 10 1 0 10 0 1 0

Side Note: DeMorgan’s Law

78

P Q AND( NOT(P) NOT(Q))

1 1 0 0 01 0 0 0 10 1 0 1 00 0 1 1 1

P Q NOT( OR(P,Q))

1 1 0 11 0 0 10 1 0 10 0 1 0

DOORCLOSED

DOOROPEN

State Machines: Sliding Doors

79

DOORCLOSED

DOOROPEN

State Machines: Sliding Doors

80

Sensors! Input! Reading from Memory!

The Computer

81

‣ Internal states (memory)

‣ Complex logic relating bits/information

‣ Mechanism for setting bits (input)

‣ Mechanism for displaying bits (output)

The Computer

82

The Computer

83

The Computer

84

The Computer

85

The Computer

86

https://xkcd.com/505/

The Church-Turing Thesis

87

Alonzo Church Alan Turing

The Church-Turing Thesis

88

“There is only one notion of computation”

The Church-Turing Thesis

89

“There is only one notion of computation”

(and anything with these properties is doing it)

‣ Internal states

‣ Complex logic relating bits

‣ Mechanism for setting bits (input)

‣ Mechanism for displaying bits (output)

The Church-Turing Thesis

90

“There is only one notion of computation”

Things that can be computed, period.

The Church-Turing Thesis

91

“There is only one notion of computation”

Things that can be computed, period.

Things a domino computer could compute

before the sun goes supernova

The Church-Turing Thesis

92

“There is only one notion of computation”

Things a regular computer can compute before the

sun goes supernova

Things that can be computed, period.

Things a domino computer could compute

before the sun goes supernova

The Church-Turing Thesis

93

“There is only one notion of computation”

Things a regular computer can compute before the sun

goes supernova

Things that can be computed, period.

Things a domino computer could compute before the

sun goes supernova

Q: What, if anything, is out here?

The Church-Turing Thesis

94

“There is only one notion of computation”

Things a regular computer can compute before the sun

goes supernova

Things that can be computed, period.

Things a domino computer could compute before the

sun goes supernova

???

Q: What, if anything, is out here?

The Church-Turing Thesis

95

“There is only one notion of computation”

Things a regular computer can compute before the sun

goes supernova

Things that can be computed, period.

Things a domino computer could compute before the

sun goes supernova

???

A: Theory unit!

Q: What, if anything, is out here?

The Church-Turing Thesis

96

“There is only one notion of computation”

‣ Some other questions:

- Is the human brain carrying out computation?

- Is the comic right? Or are there things in the world that feel like they aren’t computation?

- Is “randomness” computable? How?

- Is there one “fastest” model of a computer? (e.g. X is to the transistor as the transistor is to the domino)

The Computer

97

‣ Internal states (memory)

‣ Complex logic relating bits

‣ Mechanism for setting bits (input)

‣ Mechanism for displaying bits (output)

Q: What are these in our computers?

The Computer

98

‣ Internal states

‣ Complex logic relating bits

‣ Mechanism for setting bits (input)

‣ Mechanism for displaying bits (output)

Q: What are these in our computers?

The Computer

99

‣ Internal states

‣ Complex logic relating bits

‣ Mechanism for setting bits (input)

‣ Mechanism for displaying bits (output)

Q: What are these in our computers?

Memory

The Computer

100

‣ Internal states

‣ Complex logic relating bits

‣ Mechanism for setting bits (input)

‣ Mechanism for displaying bits (output)

Q: What are these in our computers?

Memory

CPU

The Computer

101

‣ Internal states

‣ Complex logic relating bits

‣ Mechanism for setting bits (input)

‣ Mechanism for displaying bits (output)

Q: What are these in our computers?

Memory

CPU

Mouse

Keyboard

The Computer

102

‣ Internal states

‣ Complex logic relating bits

‣ Mechanism for setting bits (input)

‣ Mechanism for displaying bits (output)

Q: What are these in our computers?

Memory

CPU

Mouse

Keyboard

Monitor

Next Time

103

‣ Internal states

‣ Complex logic relating bits

‣ Mechanism for setting bits (input)

‣ Mechanism for displaying bits (output)

Memory

CPU

Mouse

Keyboard

Monitor

Programming lets us define the

“complex logic”!