Presentation is loading. Please wait.

Presentation is loading. Please wait.

Administrivia Assignments Labs Questions?? Class questions – –Goes to dpd and the TA’s Hand in lab assignments.

Similar presentations


Presentation on theme: "Administrivia Assignments Labs Questions?? Class questions – –Goes to dpd and the TA’s Hand in lab assignments."— Presentation transcript:

1 Administrivia Assignments Labs Questions?? Class questions – cs111@cs.princeton.educs111@cs.princeton.edu –Goes to dpd and the TA’s Hand in lab assignments – cs111@princeton.educs111@princeton.edu –Goes to a file.

2 Adding Decimal Numbers 4 6 5 5 4 3 ========= We all know that the answer is 1008 but how do we do this?

3 Adding Decimal Numbers 4 6 5 5 4 3 ========= Start from the right 5+3 = 8 and there is no carry

4 Adding Decimal Numbers 4 6 5 5 4 3 ========= 8 Start from the right 5+3 = 8 and there is no carry Next, 6+4 = 10 Write the 0, carry the 1

5 Adding Decimal Numbers 1 4 6 5 5 4 3 ========= 0 8 Start from the right 5+3 = 8 and there is no carry Next, 6+4 = 10 Write the 0, carry the 1

6 Adding Decimal Numbers 1 4 6 5 5 4 3 ========= 0 8 Start from the right 5+3 = 8 and there is no carry Next, 6+4 = 10 Write the 0, carry the 1 Finally, 1+4+5 = 10 Write the 0, carry the 1

7 Adding Decimal Numbers 1 1 4 6 5 5 4 3 ========= 1 0 0 8 Start from the right 5+3 = 8 and there is no carry Next, 6+4 = 10 Write the 0, carry the 1 Finally, 1+4+5 = 10 Write the 0, carry the 1

8 Adding Decimal Numbers 1 1 4 6 5 5 4 3 ========= 1 0 0 8 Start from the right 5+3 = 8 and there is no carry Next, 6+4 = 10 Write the 0, carry the 1 Finally, 1+4+5 = 10 Write the 0, carry the 1 At each stage, take 2 addends (5 and 3 or 6 and 4 or 4 and 5) and a bit telling whether there is a carry and produce a sum bit and a bit telling if there is a carry.

9 Bad news It is inconvenient to add decimal numbers in a computer –Truth tables are easier than addition tables –The universal method wants to work from truth tables

10 Bad news/Good News Bad news – It is inconvenient to add decimal numbers in a computer –Truth tables are easier than addition tables –The universal method wants to work from truth tables Good news – the same thing works for binary numbers

11 Adding Binary Numbers At each stage, take 2 addends and a bit telling whether there is a carry and produce a sum bit and a bit telling if there is a carry.

12 Adding Binary Numbers (cont.)1 101 +111 _______________ 1100 0 + 0 =0 0 + 1 = 1 1 + 0 = 1 1 + 1 =10

13 Sidebar – what are binary numbers Base 2 rather than base 10 Decimal numbers –We write (1234) 10 to represent a decimal number that has 4 units, 3 tens, 2 hundreds and 1 thousand. –(1234) 10 = 1 x10 3 + 2 x10 2 + 3 x10 1 + 4 x10 0

14 Sidebar – what are binary numbers Base 2 rather than base 10 Decimal numbers –We write (1234) 10 to represent a decimal number that has 4 units, 3 tens, 2 hundreds and 1 thousand. –(1234) 10 = 1 x10 3 + 2 x10 2 + 3 x10 1 + 4 x10 0 Binary numbers –We write (1001) 2 to represent a decimal number that has 1 unit, 0 2’s, 0 4’s and 1 8. –(1001) 2 = 1 x2 3 + 0 x2 2 + 0 x2 1 + 1 x2 0

15 Adding Binary Numbers At each stage, take 2 addends and a bit telling whether there is a carry and produce a sum bit and a bit telling if there is a carry.

16 Adding Binary Numbers At each stage, take 2 addends and a bit telling whether there is a carry and produce a sum bit and a bit telling if there is a carry. We can build a black box to do this addend carry bit in Sum bit carry bit out

17 Adding Binary Numbers Write the numbers as –X4 X3 X2 X1 X0 –Y4 Y3 Y2 Y1 Y0 Represent the sum as –C Z4 Z3 Z2 Z1 Z0

18 Adding Binary Numbers Write the numbers as –X4 X3 X2 X1 X0 –Y4 Y3 Y2 Y1 Y0 Represent the sum as –C Z4 Z3 Z2 Z1 Z0 Start with X0, Y0, 0 in, Z0 and C0 out Then X1,Y1,C0 in and Z1 and C1 out. And so on

19 Adding Binary Numbers At the ith stage ith bit of X ith bit of Y carry bit ith bit of Z carry bit out Abstraction in action -- This is a piece of a carry-ripple adder Universal Circuit

20 Carry-Ripple Adder Z0 C0 Universal Circuit X0 Y0 Z1 C1 Universal Circuit X1 Y1 Z2 C2 Universal Circuit X2 Y2 X2 X1 X0 Y2 Y1 Y0 ============ C2 Z2 Z1 Z0 0 Fixed at 0

21 What’s inside the box? Zi Cout Universal Circuit Xi Yi Cin

22 What’s inside the box? Zi Cout Universal Circuit Xi Yi Cin Do the problem set and find out

23 Carry ripple adders Useful for some applications Too slow for other –Delay while waiting for the carry to ripple One solution – add larger blocks –Details on the homework assignment

24 Arithmetic Logical Unit (ALU) This is the part of the CPU that does arithmetic and comparison operations We’ve built a piece of the ALU With abstraction, we could build the other parts –Multiplication/subtraction/division –Comparison Then we would write a language to let the user talk to the ALU (programming)

25 Pause Questions?? How to build the other parts of the ALU? –Use abstraction Back to representing information

26 Representing information How do we represent characters? –How many characters might we want to represent? –What characters might we want to represent?

27 Representing information How do we represent characters? –How many characters might we want to represent? –What characters might we want to represent? A-Z 26 A-Z and a-z 52 All the keys on my keyboard 104 Maybe a power of 2? 128 Maybe an even power of 2? 256 Maybe an even bigger power of 2?65536

28 Representing characters ASCII is the American Standard Code for Information Interchange. It is a 7-bit code. Many 8-bit codes contain ASCII as their lower half The ASCII standard was published by the United States of America Standards Institute (USASI) in 1968.

29 Unicode Universal Character Set (UCS) contains all characters of all other character set standards. It also guarantees round-trip compatibility, i.e., conversion tables can be built such that no information is lost when a string is converted from any other encoding to UCS and back. UCS contains the characters required to represent almost all known languages. This includes apart from the many languages which use extensions of the Latin script also the following scripts and languages: Greek, Cyrillic, Hebrew, Arabic, Armenian, Gregorian, Japanese, Chinese, Hiragana, Katakana, Korean, Hangul, Devangari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada, Malayam, Thai, Lao, Bopomofo, and a number of others. Work is going on to include further scripts like Tibetian, Khmer, Runic, Ethiopian, Hieroglyphics, various Indo-European languages, and many others. It’s intended to use 31 bits (32768 possible characters)

30 What do we do in practice Problems –Bits represent too little – too many are needed –Decimal numbers don’t translate well into bits So, –Group into blocks of 4 and 8 bits 8 bits = 256 characters, holds ASCII 8 bits make 1 byte – things are organized into bytes 4 bits make 1 nibble

31 Shorthand: Hexadecimal 0123456701234567 0000000100100011010001010110011100000001001000110100010101100111 89ABCDEF89ABCDEF 1000100110101011110011011110111110001001101010111100110111101111

32 Sidebar – what are hexadecimal numbers Base 16 rather than base 10 Decimal numbers –We write (1234) 10 to represent a decimal number that has 4 units, 3 tens, 2 hundreds and 1 thousand. –(1234) 10 = 1 x10 3 + 2 x10 2 + 3 x10 1 + 4 x10 0 Hexadecimal numbers –We write (2AC4) 16 to represent a decimal number that has 1 units, 12 16’s, 10 256’s and 2 65,536’s –(2AC4) 16 = 1 x16 3 + 0 x16 2 + 0 x16 1 + 1 x16 0

33 Hexadecimal We can add numbers –1+1=2, 2+2=4, 4+4=8, 4+8=C, 2+8=A, … We can combine 2 hexadecimal numbers to make a byte. It’s easier to read than 0’s and 1’s In ASCII –hex 41 through 5A represent A to Z –Hex 61 through 7A represent a to z

34 Memory

35 Logic circuits we’ve seen so far have no memory. They just transform input to output. Can we make logic circuits that remember?

36 The Stubborn Guy Matt really likes Sue, but he doesn’t like changing his mind… so: Matt decides to go to the party if Sue decides to go OR if he (Matt) already feels like going.

37 The Stubborn Guy: Feedback Matt decides to go to the party if Sue decides to go OR if he (Matt) already feels like going. OR Sue Matt Feedback Wire

38 The Stubborn Guy: Feedback Matt decides to go to the party if Sue decides to go OR if he (Matt) already feels like going. If Sue decides to go... OR Sue Matt 1

39 The Stubborn Guy: Feedback Matt decides to go to the party if Sue decides to go OR if he (Matt) already feels like going. If Sue decides to go, Matt will go. OR Sue Matt 1 1 1

40 The Stubborn Guy: Feedback Matt decides to go to the party if Sue decides to go OR if he (Matt) already feels like going. If Sue changes her mind… OR Sue Matt 0 1 1

41 The Stubborn Guy: Feedback Matt decides to go to the party if Sue decides to go OR if he (Matt) already feels like going. If Sue changes her mind, Matt will still go! Once he decides to go, we can’t ever get Matt to change his mind. OR Sue Matt 0 1 1

42 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR if he (Matt) already feels like going, UNLESS Rita decides to go.

43 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go.

44 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go. OR AND Sue Rita Matt Feedback Wire

45 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go. OR AND Sue Rita Matt 0 0 0 0 0 1

46 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go. OR AND Sue Rita Matt 1 0 0 0 0 1

47 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go. OR AND Sue Rita Matt 1 0 1 1 1 1

48 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go. OR AND Sue Rita Matt 0 0 1 1 1 1

49 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go. OR AND Sue Rita Matt 0 – nothing changes 0 1 1 1 1

50 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go. OR AND Sue Rita Matt 0 1 1 1 1 1

51 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go. OR AND Sue Rita Matt 0 1 1 1 1 0

52 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go. OR AND Sue Rita Matt 0 1 1 1 0 0

53 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go. OR AND Sue Rita Matt 0 1 0 1 0 0

54 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go. OR AND Sue Rita Matt 0 1 0 0 0 0

55 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go. OR AND Sue Rita Matt 0 0 0 0 0 0

56 Enter Rita Matt doesn’t like Rita Matt decides to go to the party if Sue decides to go OR: If he (Matt) already feels like going AND Rita decides NOT to go. OR AND Sue Rita Matt 0 0 0 0 0 1

57 The Flip-Flop OR AND Set Reset M M becomes 1 if Set is turned on M becomes 0 if Reset is turned on Otherwise (if Set and Reset are both 0), M just remembers its value

58 The Flip-Flop M becomes 1 if Set is turned on M becomes 0 if Reset is turned on Otherwise (if Set and Reset are both 0), M just remembers its value S R M

59 AND The Data Flip-Flop Nothing happens unless Write = 1 S R M D Write

60 AND The Data Flip-Flop Nothing happens unless Write = 1 If Write = 1, then M becomes set to D Once Write = 0 again, M just keeps its value. (It ignores D.) S R M D Write

61 AND Using a Data Flip-Flop Initially, Write = 0. Let’s say M = 1. S R M D Write 0 0 0 1

62 AND Using a Data Flip-Flop Initially, Write = 0. Let’s say M = 1. First, set D to desired value, say 0. S R M D Write 0 0 0 1 0 1

63 AND Using a Data Flip-Flop Initially, Write = 0. Let’s say M = 1. First, set D to desired value, say 0. Then, set Write to 1. S R M D Write 1 0 1 1 0 1

64 AND Using a Data Flip-Flop Initially, Write = 0. Let’s say M = 1. First, set D to desired value, say 0. Then, set Write to 1. This causes M to be reset to 0. S R M D Write 1 0 1 0 0 1

65 AND Using a Data Flip-Flop Initially, Write = 0. Let’s say M = 1. First, set D to desired value, say 0. Then, set Write to 1. This causes M to be reset to 0. Finally set Write back to 0. Now D irrelevant. S R M D Write 0 0 0 0 ? 1

66 The Data Flip-Flop If Write = 0, M just keeps its value. (It ignores D.) If Write = 1, then M becomes set to D D Write M

67 A subtle problem When Write = 1, then M = D. If we have some feedback between M and D, then circuit could go haywire. D Write M ??

68 A subtle problem For example, suppose NOT gate connects M and D. When Write = 1, M and D keep changing. We have no control. D Write M NOT 1 ? ?

69 A subtle problem We want to control the feedback, so that each time we set Write to 1 and then back to 0, M stores only the last value of D (In this case, M should invert itself once each time we set Write to 1 and back to 0) D Write M NOT 1 ? ?

70 “Airlock” Flip-Flop D1D1 W1W1 M1M1 D0D0 W0W0 M0M0 “Outer door” “Inner door” Write Two-Stage System to prevent feedback loop. D M

71 “Airlock” Flip-Flop D1D1 W1W1 M1M1 D0D0 W0W0 M0M0 “Outer door” “Inner door” Write We start with Write = 0. Let’s say D is always NOT M. Start with D = 0, M = 1. D M

72 “Airlock” Flip-Flop D1D1 W1W1 M1M1 D0D0 W0W0 M0M0 “Outer door” “Inner door” Write We start with Write = 0. Let’s say D is always NOT M. Start with D = 0, M = 1. D M 0 0 1 1 1

73 “Airlock” Flip-Flop D1D1 W1W1 M1M1 D0D0 W0W0 M0M0 “Outer door” “Inner door” Write Want to store D in memory. Set Write to 1 D M 1 0 0 1 1

74 “Airlock” Flip-Flop D1D1 W1W1 M1M1 D0D0 W0W0 M0M0 “Outer door” “Inner door” Write Want to store D in memory. Set Write to 1 “Outer” flip-flop sets M 0 = D 0 = 0 “Inner” flip-flop ignores D 1 since W 1 = 0 D M 1 0 0 0 1

75 “Airlock” Flip-Flop D1D1 W1W1 M1M1 D0D0 W0W0 M0M0 “Outer door” “Inner door” Write Now, set Write back to 0 D M 0 0 1 0 1

76 “Airlock” Flip-Flop D1D1 W1W1 M1M1 D0D0 W0W0 M0M0 “Outer door” “Inner door” Write Now, set Write back to 0 Now “Inner” flip-flop sets M = D 1 = 0 D M 0 0 1 0 0

77 “Airlock” Flip-Flop D1D1 W1W1 M1M1 D0D0 W0W0 M0M0 “Outer door” “Inner door” Write Because of feedback, D might change to (NOT M), which is 1 But Write = 0, so “Outer” flip-flop ignores D, and so M 0 stays 0. D M 0 1 1 0 0

78 “Airlock” Flip-Flop D1D1 W1W1 M1M1 D0D0 W0W0 M0M0 “Outer door” “Inner door” Write So memory does not change until we “toggle” Write. (“toggle” means change from 0 to 1 or vice versa) D M 0 1 1 0 0

79 “Airlock” Flip-Flop D1D1 W1W1 M1M1 D0D0 W0W0 M0M0 “Outer door” “Inner door” Write This is Real Memory! D M

80 Memory “Register”: 4 bits D M W D M W D M W D M W Write Data 1 Data 2 Data 3 Data 4

81 Review We have used the Universal method to build –ALU –Memory Next steps –State machines to computer with memory –Building the computer –Writing a program to use the computer


Download ppt "Administrivia Assignments Labs Questions?? Class questions – –Goes to dpd and the TA’s Hand in lab assignments."

Similar presentations


Ads by Google