Title: Administrivia
1Administrivia
- Assignments
- Labs
- Questions??
- Class questions cs111_at_cs.princeton.edu
- Goes to dpd and the TAs
- Hand in lab assignments cs111_at_princeton.edu
- Goes to a file.
2Adding Decimal Numbers
4 6 5 5 4 3
We all know that the answer is 1008 but how do
we do this?
3Adding Decimal Numbers
4 6 5 5 4 3
Start from the right 53 8 and there is no carry
4Adding Decimal Numbers
4 6 5 5 4 3
8
Start from the right 53 8 and there is no carry
Next, 64 10 Write the 0, carry the 1
5Adding Decimal Numbers
1 4 6 5 5 4
3 0 8
Start from the right 53 8 and there is no carry
Next, 64 10 Write the 0, carry the 1
6Adding Decimal Numbers
1 4 6 5 5 4
3 0 8
Start from the right 53 8 and there is no carry
Next, 64 10 Write the 0, carry the 1
Finally, 145 10 Write the 0, carry the 1
7Adding Decimal Numbers
1 1 4 6 5 5 4
3 1 0 0 8
Start from the right 53 8 and there is no carry
Next, 64 10 Write the 0, carry the 1
Finally, 145 10 Write the 0, carry the 1
8Adding Decimal Numbers
1 1 4 6 5 5 4
3 1 0 0 8
Start from the right 53 8 and there is no
carry Next, 64 10 Write the 0, carry the
1 Finally, 145 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.
9Bad 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
10Bad 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
11Adding 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.
12Adding Binary Numbers (cont.)
1 1 1 0 1 1 1 1 _______________
1 1 0 0
0 0 0 0 1 1 1 0 1 1 1 10
13Sidebar 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 x103 2 x102 3 x101 4 x100
14Sidebar 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 x103 2 x102 3 x101 4 x100
- Binary numbers
- We write (1001)2 to represent a decimal number
that has 1 unit, 0 2s, 0 4s and 1 8. - (1001)2 1 x23 0 x22 0 x21 1 x20
15Adding 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.
16Adding 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
Sum bit
addend
carry bit out
carry bit in
17Adding 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
18Adding 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
19Adding Binary Numbers
At the ith stage
ith bit of X
Universal Circuit
ith bit of Z
ith bit of Y
carry bit out
carry bit
Abstraction in action -- This is a piece of a
carry-ripple adder
20Carry-Ripple Adder
Z1
Z2
Universal Circuit
X2
Z0
Universal Circuit
X1
Universal Circuit
X0
C2
Y2
Y0
Y1
C1
C0
0
Fixed at 0
X2 X1 X0 Y2 Y1
Y0 C2 Z2 Z1 Z0
21Whats inside the box?
Zi
Universal Circuit
Xi
Yi
Cout
Cin
22Whats inside the box?
Zi
Universal Circuit
Xi
Yi
Cout
Cin
Do the problem set and find out
23Carry 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
24Arithmetic Logical Unit (ALU)
- This is the part of the CPU that does arithmetic
and comparison operations - Weve 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)
25Pause
- Questions??
- How to build the other parts of the ALU?
- Use abstraction
- Back to representing information
26Representing information
- How do we represent characters?
- How many characters might we want to represent?
- What characters might we want to represent?
27Representing 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
28Representing 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.
29Unicode
- 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. - Its intended to use 31 bits (32768 possible
characters)
30What do we do in practice
- Problems
- Bits represent too little too many are needed
- Decimal numbers dont 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
31Shorthand Hexadecimal
32Sidebar 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 x103 2 x102 3 x101 4 x100
- Hexadecimal numbers
- We write (2AC4)16 to represent a decimal number
that has 1 units, 12 16s, 10 256s and 2
65,536s - (2AC4)16 1 x163 0 x162 0 x161 1 x160
33Hexadecimal
- We can add numbers
- 112, 224, 448, 48C, 28A,
- We can combine 2 hexadecimal numbers to make a
byte. - Its easier to read than 0s and 1s
- In ASCII
- hex 41 through 5A represent A to Z
- Hex 61 through 7A represent a to z
34Memory
35Memory
- Logic circuits weve seen so far have no memory.
They just transform input to output. - Can we make logic circuits that remember?
36The Stubborn Guy
- Matt really likes Sue, but he doesnt
likechanging his mind so - Matt decides to go to the party if Sue decides to
go OR if he (Matt) already feels like going.
37The Stubborn Guy Feedback
- Matt decides to go to the party if Sue decides to
go OR if he (Matt) already feels like going.
Sue
Matt
Feedback Wire
38The 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...
1
Sue
Matt
39The 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.
1
Sue
1
Matt
1
40The 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
0
Sue
1
Matt
1
41The 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 cant ever get Matt to
change his mind.
0
Sue
1
Matt
1
42Enter Rita
- Matt doesnt 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.
43Enter Rita
- Matt doesnt 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.
44Enter Rita
- Matt doesnt 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.
Sue
Matt
Rita
Feedback Wire
45Enter Rita
- Matt doesnt 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.
0
Sue
0
Matt
1
0
Rita
0
0
46Enter Rita
- Matt doesnt 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.
1
Sue
0
Matt
1
0
Rita
0
0
47Enter Rita
- Matt doesnt 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.
1
Sue
1
Matt
1
1
Rita
0
1
48Enter Rita
- Matt doesnt 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.
0
Sue
1
Matt
1
1
Rita
0
1
49Enter Rita
- Matt doesnt 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.
0 nothing changes
Sue
1
Matt
1
1
Rita
0
1
50Enter Rita
- Matt doesnt 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.
0
Sue
1
Matt
1
1
Rita
1
1
51Enter Rita
- Matt doesnt 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.
0
Sue
1
Matt
0
1
Rita
1
1
52Enter Rita
- Matt doesnt 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.
0
Sue
1
Matt
0
0
Rita
1
1
53Enter Rita
- Matt doesnt 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.
0
Sue
0
Matt
0
0
Rita
1
1
54Enter Rita
- Matt doesnt 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.
0
Sue
0
Matt
0
0
Rita
1
0
55Enter Rita
- Matt doesnt 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.
0
Sue
0
Matt
0
0
Rita
0
0
56Enter Rita
- Matt doesnt 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.
0
Sue
0
Matt
1
0
Rita
0
0
57The Flip-Flop
Set
M
Reset
- 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
58The Flip-Flop
S
M
R
- 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
59The Data Flip-Flop
S
D
Write
M
R
- Nothing happens unless Write 1
60The Data Flip-Flop
S
D
Write
M
R
- 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.)
61Using a Data Flip-Flop
0
S
D
1
Write
0
M
R
0
- Initially, Write 0. Lets say M 1.
62Using a Data Flip-Flop
0
S
0
D
1
Write
0
M
R
0
1
- Initially, Write 0. Lets say M 1.
- First, set D to desired value, say 0.
63Using a Data Flip-Flop
0
S
0
D
1
Write
1
M
R
1
1
- Initially, Write 0. Lets say M 1.
- First, set D to desired value, say 0.
- Then, set Write to 1.
64Using a Data Flip-Flop
0
S
0
D
0
Write
1
M
R
1
1
- Initially, Write 0. Lets say M 1.
- First, set D to desired value, say 0.
- Then, set Write to 1.
- This causes M to be reset to 0.
65Using a Data Flip-Flop
0
S
?
D
0
Write
0
M
R
0
1
- Initially, Write 0. Lets 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.
66The Data Flip-Flop
D
M
Write
- If Write 0, M just keeps its value.(It ignores
D.) - If Write 1, then M becomes set to D
67A subtle problem
D
M
??
Write
- When Write 1, then M D.
- If we have some feedback between M and D,then
circuit could go haywire.
68A subtle problem
?
D
?
M
1
Write
- For example, suppose NOT gate connectsM and D.
- When Write 1, M and D keep changing. We have
no control.
69A subtle problem
?
D
?
M
1
Write
- We want to control the feedback, so thateach
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)
70Airlock Flip-Flop
Outer door
Inner door
M
D
M1
D1
D0
M0
Write
W1
W0
- Two-Stage System to prevent feedback loop.
71Airlock Flip-Flop
Outer door
Inner door
M
D
M1
D1
D0
M0
Write
W1
W0
- We start with Write 0.
- Lets say D is always NOT M.Start with D 0, M
1.
72Airlock Flip-Flop
Outer door
Inner door
0
M
1
1
D
M1
D1
D0
M0
1
0
Write
W1
W0
- We start with Write 0.
- Lets say D is always NOT M.Start with D 0, M
1.
73Airlock Flip-Flop
Outer door
Inner door
0
M
1
1
D
M1
D1
D0
M0
0
1
Write
W1
W0
- Want to store D in memory.
- Set Write to 1
74Airlock Flip-Flop
Outer door
Inner door
0
M
1
0
D
M1
D1
D0
M0
0
1
Write
W1
W0
- Want to store D in memory.
- Set Write to 1
- Outer flip-flop sets M0 D0 0
- Inner flip-flop ignores D1 since W1 0
75Airlock Flip-Flop
Outer door
Inner door
0
M
1
0
D
M1
D1
D0
M0
1
0
Write
W1
W0
76Airlock Flip-Flop
Outer door
Inner door
0
M
0
0
D
M1
D1
D0
M0
1
0
Write
W1
W0
- Now, set Write back to 0
- Now Inner flip-flop sets M D1 0
77Airlock Flip-Flop
Outer door
Inner door
1
M
0
0
D
M1
D1
D0
M0
1
0
Write
W1
W0
- Because of feedback, D might change to (NOT M) ,
which is 1 - But Write 0, so Outer flip-flop ignores
D,and so M0 stays 0.
78Airlock Flip-Flop
Outer door
Inner door
1
M
0
0
D
M1
D1
D0
M0
1
0
Write
W1
W0
- So memory does not change until we toggle
Write. - (toggle means change from 0 to 1 or vice versa)
79Airlock Flip-Flop
Outer door
Inner door
M
D
M1
D1
D0
M0
Write
W1
W0
80Memory Register 4 bits
Data1
D
M
W
Data2
D
M
W
Data3
D
M
W
Data4
D
M
Write
W
81Review
- 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