administrivia assignments labs questions?? class questions –...
Post on 19-Dec-2015
216 views
TRANSCRIPT
Administrivia
• Assignments• Labs• Questions??• Class questions – [email protected]
– Goes to dpd and the TA’s
• Hand in lab assignments – [email protected]– Goes to a file.
Adding Decimal Numbers
4 6 5 5 4 3=========
We all know that the answer is 1008 but how do we do this?
Adding Decimal Numbers
4 6 5 5 4 3========= 8
Start from the right5+3 = 8 and there isno carry
Next, 6+4 = 10Write the 0, carry the 1
Adding Decimal Numbers 1
4 6 5 5 4 3========= 0 8
Start from the right5+3 = 8 and there isno carry
Next, 6+4 = 10Write the 0, carry the 1
Adding Decimal Numbers 1
4 6 5 5 4 3========= 0 8
Start from the right5+3 = 8 and there isno carry
Next, 6+4 = 10Write the 0, carry the 1
Finally, 1+4+5 = 10Write the 0, carry the 1
Adding Decimal Numbers 1 1
4 6 5 5 4 3========= 1 0 0 8
Start from the right5+3 = 8 and there isno carry
Next, 6+4 = 10Write the 0, carry the 1
Finally, 1+4+5 = 10Write the 0, carry the 1
Adding Decimal Numbers 1 1
4 6 5 5 4 3========= 1 0 0 8
Start from the right5+3 = 8 and there is no carryNext, 6+4 = 10Write the 0, carry the 1Finally, 1+4+5 = 10Write 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 acarry and produce a sum bit and a bit telling if there is a carry.
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
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
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.
Adding 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
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 x103 + 2 x102 + 3 x101 + 4 x100
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 x103 + 2 x102 + 3 x101 + 4 x100
• 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 x23 + 0 x22 + 0 x21 + 1 x20
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.
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
addend
carry bit in
Sum bit
carry bit out
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
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
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
Carry-Ripple Adder
Z0
C0
UniversalCircuit
X0
Y0
Z1
C1
UniversalCircuit
X1
Y1
Z2
C2
UniversalCircuit
X2
Y2
X2 X1 X0 Y2 Y1 Y0============C2 Z2 Z1 Z0
0
Fixed at 0
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
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)
Pause
• Questions??
• How to build the other parts of the ALU?– Use abstraction
• Back to representing information
Representing information
• How do we represent characters?– How many characters might we want to
represent?– What characters might we want to represent?
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
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.
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)
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
Shorthand: Hexadecimal
0
1
2
3
4
5
6
7
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
8
9
A
B
C
D
E
F
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
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 x103 + 2 x102 + 3 x101 + 4 x100
• 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 x163 + 0 x162 + 0 x161 + 1 x160
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
Memory
• Logic circuits we’ve seen so far have no memory. They just transform input to output.
• Can we make logic circuits that remember?
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.
The Stubborn Guy: Feedback• Matt decides to go to the party if Sue
decides to go OR if he (Matt) already feels like going.
ORSue
Matt
FeedbackWire
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...
ORSue
Matt1
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.
ORSue
Matt1
1
1
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…
ORSue
Matt0
1
1
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.
ORSue
Matt0
1
1
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.
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.
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
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
Matt0
0
0
0
01
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
Matt1
0
0
0
01
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
Matt1
0
1
1
11
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
Matt0
0
1
1
11
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
Matt0 – nothing changes
0
1
1
11
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
Matt0
1
1
1
11
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
Matt0
1
1
1
10
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
Matt0
1
1
1
00
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
Matt0
1
0
1
00
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
Matt0
1
0
0
00
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
Matt0
0
0
0
00
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
Matt0
0
0
0
01
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
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
AND
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
MD Write
AND
AND
Using a Data Flip-Flop
• Initially, Write = 0. Let’s say M = 1.
• First, set D to desired value, say 0.
S
R
MD Write 0
0
0
10
1
AND
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
MD Write 1
0
1
10
1
AND
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
MD Write 1
0
1
00
1
AND
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
MD Write 0
0
0
0?
1
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
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 ??
A subtle problem
• For example, suppose NOT gate connectsM and D.
• When Write = 1, M and D keep changing. We have no control.
D
Write
M NOT
1
?
?
A subtle problem
• 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)
D
Write
M NOT
1
?
?
“Airlock” Flip-Flop
D1
W1
M1D0
W0
M0
“Outer door” “Inner door”
Write
• Two-Stage System to prevent feedback loop.
D M
“Airlock” Flip-Flop
D1
W1
M1D0
W0
M0
“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
“Airlock” Flip-Flop
D1
W1
M1D0
W0
M0
“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
“Airlock” Flip-Flop
D1
W1
M1D0
W0
M0
“Outer door” “Inner door”
Write
• Want to store D in memory.
• Set Write to 1
D M
1
0
0
1 1
“Airlock” Flip-Flop
D1
W1
M1D0
W0
M0
“Outer door” “Inner door”
Write
• 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
D M
1
0
0
0 1
“Airlock” Flip-Flop
D1
W1
M1D0
W0
M0
“Outer door” “Inner door”
Write
• Now, set Write back to 0
D M
0
0
1
0 1
“Airlock” Flip-Flop
D1
W1
M1D0
W0
M0
“Outer door” “Inner door”
Write
• Now, set Write back to 0
• Now “Inner” flip-flop sets M = D1 = 0
D M
0
0
1
0 0
“Airlock” Flip-Flop
D1
W1
M1D0
W0
M0
“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 M0 stays 0.
D M
0
1
1
0 0
“Airlock” Flip-Flop
D1
W1
M1D0
W0
M0
“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