1/30/13 CS101 Lecture 06: Logic Gates + Binary Addition = The Adder Review Logic Gates Adding Binary Numbers Aaron Stevens (azs@bu.edu) 30 January 2013 Computer Science What You’ll Learn Today Computer Science Review: logic gates Review: How do we add in binary? Combining logic gates in a single circuit. Logic gates + binary addition = digital computing Why should you care? This is what a computer actually does! WTF? Exactly. 2 1 1/30/13 Review: AND Gate Computer Science The AND gate accepts two input signals. The output is 1 if and only if both inputs are 1. Otherwise the output is 0. Just like wiring in series. 3 Review: OR Gate Computer Science The OR gate accepts two input signals. The output is 1 if either input is 1. The output is 0 if both inputs are 0. Just like wiring in parallel. 4 2 1/30/13 Review: XOR Gate Computer Science An XOR gate accepts two input signals. When the 2 inputs differ, the output is 1 When both inputs are the same, the output is 0 Just like wiring with a 3-way switch. 5 Binary: Add with Carry Computer Science 0 + 0 is a sum of 0 with a carry of 0 1 + 0 is a sum of 1 with a carry of 0 0 + 1 is a sum of 1 with a carry of 0 1 + 1 is a sum of 0 with a carry of 1 ! Operands ! ! ! 1 0 + 0 1 Hint: work right to left. 1 1 0 0 0 1 1 0 ! 1! 0 ! 1! Carry Values Sum 6 14 3 1/30/13 An 8-bit Adder Computer Science Consider this 8-bit adder: Notice how the carry out from one bit’s adder becomes the carry-in to the next adder. http://faculty.mc3.edu/pvetere/Applets/APPLETS/BINARYADD/applet_frame.htm 7 A binary Adding Machine Computer Science http://www.youtube.com/watch?v=GcDshWmhF4A 4 1/30/13 Combinational Circuits Computer Science Combines some basic gates (AND, OR, XOR, NOT) into a more complex circuit. Outputs from one circuit flow into the inputs of another circuit. The input values explicitly determine the output values. 9 Combinational Circuits Computer Science Three inputs require eight rows to describe all possible input combinations (23 = 8): 10 5 1/30/13 Binary Number Addition Computer Science Look closely at the values for Sum and Carry… Do they look like any of the gates we’ve seen? 11 A Circuit for Binary Addition Computer Science Sum = A XOR B Carry = A AND B This circuit is called a half-adder. (It doesn’t take a carry-in.) 12 6 1/30/13 Full Adder Circuit Computer Science The full adder takes 3 inputs: A, B, and a carry-in value 13 The Full Adder Computer Science Here is the Full Adder, with its internal details hidden (an abstraction). What matters now are: inputs are A, B, and CI. outputs are S and CO 14 7 1/30/13 An 8-bit Adder Computer Science Consider this 8-bit adder: Notice how the carry out from one bit’s adder becomes the carry-in to the next adder. http://faculty.mc3.edu/pvetere/Applets/APPLETS/BINARYADD/applet_frame.htm 15 An 8-bit Adder Computer Science To add two 8-bit numbers together, we need an 8-bit adder: Notice how the carry out from one bit’s adder becomes the carry-in to the next adder. 16 8 1/30/13 An 8-bit Adder Computer Science We can abstract away the 1-bit adders, And summarize with this diagram: Notice the inputs and outputs. 17 Number Overflow Computer Science If each value is stored using eight bits, consider adding 250 + 9: 11111010! !(8 bits)! + 00001001! !(8 bits) 00000011! !(8 bits) How do we interpret the value 00000011? 250 + 9 = 3. WTF? This is called overflow. 18 9 1/30/13 Number Overflow Computer Science Adding two 8-bit numbers can result in an 9 bit result. More generally, adding 2 n-bit numbers can give a n+1 bit result. Can we trust the sum? What does one do about overflow? 19 What You Learned Today Computer Science Basic logic gates (AND, OR, XOR) Combination gates Half-Adder Full Adder Overflow 20 10 1/30/13 Announcements And To Do Computer Science Readings: Reed chapter 7, pp121-131 Wikipedia: http://en.wikipedia.org/wiki/VLSI (introductory remarks about gates on integrated circuits) HW02 due tonight HW03 due next week Quiz 1 on Friday 2/1 Covers material from lectures 1-4 (i.e., not including this week) 21 11