Download Fundamentals of Computer Systems and more Lecture notes Algorithms and Programming in PDF only on Docsity! Fundamentals of Computer Systems Thinking Digitally Stephen A. Edwards and Martha Kim Columbia University Spring 2012 The Subject s of this Class 0 1 Engineering Works Because of Abstraction Application Software Operating Systems Architecture Micro-Architecture Logic Digital Circuits Analog Circuits Devices Physics Engineering Works Because of Abstraction Application Software COMS 3157, 4156, et al. Operating Systems COMS W4118 Architecture Second Half of 3827 Micro-Architecture Second Half of 3827 Logic First Half of 3827 Digital Circuits First Half of 3827 Analog Circuits ELEN 3331 Devices ELEN 3106 Physics ELEN 3106 et al. Boring Stuff Mailing list: csee3827-staff@lists.cs.columbia.edu http://www.cs.columbia.edu/~sedwards/classes/2012/3827-spring/ Prof. Stephen A. Edwards First Half of Semester sedwards@cs.columbia.edu 462 Computer Science Building Prof. Martha Kim Second Half of Semester martha@cs.columbia.edu 469 Computer Science Building Lectures 1:10–2:25 PM, Mon, Wed, 614 Schermerhorn Jan 18–Apr 30 Holidays: Mar 12–16 (Spring Break) The Text David Harris and Sarah Harris. Digital Design and Computer Architecture. Morgan-Kaufmann, 2007. Almost precisely right for the scope of this class: digital logic and computer architecture Oat =larcWee l=) A At AO A 983
of people in the world:
Those who understand binary
and those who don't.
thinkgeek.com
Which Numbering System Should We Use? Some Older Choices: Roman: I II III IV V VI VII VIII IX X Mayan: base 20, Shell = 0 Babylonian: base 60 Binary and Octal D E C PD P- 8 /I , c. 1 9 6 8 Oct Bin 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 PC = 0× 211 + 1× 210 + 0× 29 + 1× 28 + 1× 27 + 0× 26 + 1× 25 + 1× 24 + 1× 23 + 1× 22 + 0× 21 + 1× 20 = 2× 83 + 6× 82 + 7× 81 + 5× 80 = 146910 Hexadecimal Numbers Base 16: 0 1 2 3 4 5 6 7 8 9 A B C D E F Instead of groups of 3 bits (octal), Hex uses groups of 4. CAFEF00D16 = 12× 167 + 10× 166 + 15× 165 + 14× 164 + 15× 163 + 0× 162 + 0× 161 + 13× 160 = 3,405,705,22910 C A F E F 0 0 D Hex 11001010111111101111000000001101 Binary 3 1 2 7 7 5 7 0 0 1 5 Octal Computers Rarely Manipulate True Numbers Infinite memory still very expensive Finite-precision numbers typical 32-bit processor: naturally manipulates 32-bit numbers 64-bit processor: naturally manipulates 64-bit numbers How many different numbers can you represent with 5 binary octal decimal hexadecimal digits? Decimal Addition Algorithm 1 1 434 +628 106 2 4+ 8 = 12 1+ 3+ 2 = 6 4+ 6 = 10 + 0 1 2 3 4 5 6 7 8 9 0 0 1 2 3 4 5 6 7 8 9 1 1 2 3 4 5 6 7 8 9 10 2 2 3 4 5 6 7 8 9 10 11 3 3 4 5 6 7 8 9 10 11 12 4 4 5 6 7 8 9 10 11 12 13 5 5 6 7 8 9 10 11 12 13 14 6 6 7 8 9 10 11 12 13 14 15 7 7 8 9 10 11 12 13 14 15 16 8 8 9 10 11 12 13 14 15 16 17 9 9 10 11 12 13 14 15 16 17 18 10 10 11 12 13 14 15 16 17 18 19 Decimal Addition Algorithm 1 1 434 +628 10 62 4+ 8 = 12 1+ 3+ 2 = 6 4+ 6 = 10 + 0 1 2 3 4 5 6 7 8 9 0 0 1 2 3 4 5 6 7 8 9 1 1 2 3 4 5 6 7 8 9 10 2 2 3 4 5 6 7 8 9 10 11 3 3 4 5 6 7 8 9 10 11 12 4 4 5 6 7 8 9 10 11 12 13 5 5 6 7 8 9 10 11 12 13 14 6 6 7 8 9 10 11 12 13 14 15 7 7 8 9 10 11 12 13 14 15 16 8 8 9 10 11 12 13 14 15 16 17 9 9 10 11 12 13 14 15 16 17 18 10 10 11 12 13 14 15 16 17 18 19 Decimal Addition Algorithm 1 1 434 +628 1 062 4+ 8 = 12 1+ 3+ 2 = 6 4+ 6 = 10 + 0 1 2 3 4 5 6 7 8 9 0 0 1 2 3 4 5 6 7 8 9 1 1 2 3 4 5 6 7 8 9 10 2 2 3 4 5 6 7 8 9 10 11 3 3 4 5 6 7 8 9 10 11 12 4 4 5 6 7 8 9 10 11 12 13 5 5 6 7 8 9 10 11 12 13 14 6 6 7 8 9 10 11 12 13 14 15 7 7 8 9 10 11 12 13 14 15 16 8 8 9 10 11 12 13 14 15 16 17 9 9 10 11 12 13 14 15 16 17 18 10 10 11 12 13 14 15 16 17 18 19 Binary Addition Algorithm 1001 1 10011 +11001 10110 0 1+ 1 = 10 1+ 1+ 0 = 10 1+ 0+ 0 = 01 0+ 0+ 1 = 01 0+ 1+ 1 = 10 + 0 1 0 00 01 1 01 10 10 10 11 Binary Addition Algorithm 100 11 10011 +11001 1011 00 1+ 1 = 10 1+ 1+ 0 = 10 1+ 0+ 0 = 01 0+ 0+ 1 = 01 0+ 1+ 1 = 10 + 0 1 0 00 01 1 01 10 10 10 11 Binary Addition Algorithm 10 011 10011 +11001 101 100 1+ 1 = 10 1+ 1+ 0 = 10 1+ 0+ 0 = 01 0+ 0+ 1 = 01 0+ 1+ 1 = 10 + 0 1 0 00 01 1 01 10 10 10 11 Signed Numbers: Dealing with Negativity How should both positive and negative numbers be represented? Signed Magnitude Numbers You are most familiar with this: negative numbers have a leading − In binary, a leading 1 means negative: 00002 = 0 00102 = 2 10102 = −2 11112 = −7 10002 = −0? Can be made to work, but addition is annoying: If the signs match, add the magnitudes and use the same sign. If the signs differ, subtract the smaller number from the larger; return the sign of the larger. One’s Complement Numbers Like Signed Magnitude, a leading 1 indicates a negative One’s Complement number. To negate a number, complement (flip) each bit. 00002 = 0 00102 = 2 11012 = −2 10002 = −7 11112 = −0? Addition is nicer: just add the one’s complement numbers as if they were normal binary. Really annoying having a −0: two numbers are equal if their bits are the same or if one is 0 and the other is −0. Number Representations Compared Bits Binary Signed One’s Two’s Mag. Comp. Comp. 0000 0 0 0 0 0001 1 1 1 1 ... 0111 7 7 7 7 1000 8 −0 −7 −8 1001 9 −1 −6 −7 ... 1110 14 −6 −1 −2 1111 15 −7 −0 −1 Smallest number Largest number Fixed-point Numbers How to represent fractional numbers? In decimal, we continue with negative powers of 10: 31.4159 = 3× 101 + 1× 100 + 4× 10−1 + 1× 10−2 + 5× 10−3 + 9× 10−4 The same trick works in binary: 1011.01102 = 1× 23 + 0× 22 + 1× 21 + 1× 20 + 0× 2−1 + 1× 2−2 + 1× 2−3 + 0× 2−4 = 8+ 2+ 1+ 0.25+ 0.125 = 11.375 F F a u c Interesting The ancient Egyptians used binary fractions: The Eye of Horus BCD Addition Binary addition followed by a possible correction. Any four-bit group greater than 9 must have 6 added to it. Example: 11 158 +242 400 1 1 000101011000 +001001000010 1010 First group + 0110 Correction 10100000 Second group + 0110 Correction 01000000 Third group (No correction) 010000000000 Result BCD Addition Binary addition followed by a possible correction. Any four-bit group greater than 9 must have 6 added to it. Example: 11 158 +242 400 1 1 000101011000 +001001000010 1010 First group + 0110 Correction 10100000 Second group + 0110 Correction 01000000 Third group (No correction) 010000000000 Result BCD Addition Binary addition followed by a possible correction. Any four-bit group greater than 9 must have 6 added to it. Example: 1 1 158 +242 40 0 1 1 000101011000 +001001000010 1010 First group + 0110 Correction 10100000 Second group + 0110 Correction 01000000 Third group (No correction) 010000000000 Result