A Basic Computer
From CDS 130
Contents 
1. Objectives
 To understand how logic gates can be configured and combined to create logic tables that correspond to computation.
2. Motivation
 Computation can be done using combinations of logic gates.
 The process of translating a problem to a logic table and then a digital circuit is similar to the process that you will use in solving science problems with a computer: convert science questions to a math equation and then convert the math equations to a computer program.
3. Priming questions
4. Notes
4.1. Motivation
 The last step for making a computer is to combine logic gates to do a computation.
 Once you understand how that works, we will write computer programs that give the computer computation instructions (programming!).
 In our case we
 learned some of the basic tools (binary numbers, binary addition, bit patterns)
 learned some of the parts in a computer (transistors, logic gates)
 built a simple computer using these parts (will do that today)
 wrote programs to manipulate a computer (starting next week)
Note that between the last two steps there is a lot of effort involved  many of these topics are covered in advanced computer science classes.
4.2. Adding Binary Numbers prelude
 We want to use logic gates to do binary addition. But logic gates use logic tables. How can we relate a logic table to binary addition?
 First let me tell you how I use a logic table to decide what colors to wear.
 In the first four columns, a zero means "black" and a one means "brown".
 In the last column, a zero means "combination does not match", and a one means "combination matches".
 To figure out if the clothing I selected matches, I look for the row in the table that corresponds to my selection.
Socks  Pants  Shirt  Shoes  Matches?  

0  0  0  0  1  
0  1  0  1  0  
1  0  0  1  0  
0  0  1  1  0  
1  0  0  0  0  
0  1  1  0  0  
1  0  1  0  0  
1  1  1  1  1 
4.3. Adding Binary Numbers prelude
 Eventually I got lazy and wanted an easier way to figure out if I was going to match.
 So I installed four light switches that were connected to a bulb in my closet.
 I would then flip the light switches on or off according to the colors of the socks, pants, shirt, and shoes that I selected. If the bulb turned on, I made a matching selection.

4.4. Adding Binary Numbers
 We want to use logic gates to do binary addition. But logic gates use logic tables.
 The big question: How can we relate a logic table to binary addition?
1 1 1 1 + 1 1 ____ 1 1 0 A typical binary addition calculation 
Co Ci A + B __ Sp

4.5. To add any binary numbers
The following table tells us what to put for Sp and Co given any possible combinations of inputs A, B, and Ci. When you do binary addition by hand, you look at the values of A, B, and Ci and then decide the value of Sp and Co. The following table is a list of all possible inputs and the corresponding outputs.
Now that the table is built, we can try to figure out how to combine logic gates to produce this logic table.

Co Ci B + A __ Sp 
4.6. 1bit adder
If you wanted add 1+1+1 without thinking, you could flip all of the switches down and then look at what happened to the lights. If they both light up, you would say 1+1+1 must be 11.
The configuration shown below is supposed to be able to produce the logic table shown. The inputs are three switches (on = 1 = down) and the outputs are the light bulbs (on = light).
The combination of logic gates shown represents a computer that can compute sum of two 1bit numbers. Instead of having a keyboard or buttons to input information, this computer uses switches. Instead of having a monitor or screen to display output, this computer uses light bulbs.
This basic configuration can be built upon to create a computer that computes the sum of two 8bit numbers.

5. Questions
Many of these questions use the program Logicly. This video show how to use the program.
5.1. Decision table
Develop a logic table and corresponding logic circuit for making a decision in the same way that I did for deciding if my outfit matches. Post a screenshot of your circuit. Make sure that you explain what the on/off state of the switches means and what a lit/unlit bulb means. Your logic table must have at least four inputs.
5.2. Bird brain
In this problem you will practice translating a set of statements about a system (a bird) to a logic diagram. Read [3] and answer the following question. Post a screenshot to your wiki page.
Create a circuit using http://logic.ly/demo that reproduces Table 2 at [4]. Label the inputs and outputs appropriately (That is, tell me what a switch in the on or off position in corresponds to in Table 2. What does a lit/unlit bulb correspond to in Table 2?.)
See also [5].
5.3. NOR gate using NANDs
Use [6] to create a the NOR gate logic table (given below) using only NAND gates. Post a screenshot showing that your circuit gives the correct result for the first row of the NOR logic table.
Logic table for NOR gate

Student Solution 

Solution: I used Logic_Gates#NOR_Gate_using_NANDs to figure out how to combine NAND gates to give an NOR Gate. 
5.4. OR gate with NANDs
Use [7] to modify the circuit shown that it only uses NAND gates but produces the same result. Post a screenshot on your wiki page.
Student Solution 

6. Activities
6.1. logic.ly
6.1.1. logic.ly introduction
http://logic.ly/demo is a program that allows you to combine logic gates and switches. Each of the four configurations shown correspond to a row in the AND logic table. The "both switches off" case corresponds to the first row in the logic table. The "both switches on" case corresponds to the last row in the logic table. Here is how to translate the numbers in the table to the symbols in the diagram:

AND logic table

6.1.2. Using logic.ly
 Start up http://logic.ly/demo and wire together gates, switches, and bulbs as on the image in #Using_logic.ly. Verify that the four switch configurations give the same result as that shown in the image.
 Figure out the XNOR logic table by connecting switches to a XNOR gate and then writing down what various configurations of the switches (input) gives for the light bulb (output).
 Verify that the table for the 1bit adder is correct by selecting the onebit adder and flipping the switches into different configurations.
This video shows how to do the first two steps.
6.2. Bird brain
In this problem you will practice translating a set of statements about a system (a bird) to a logic circuit. This problem is similar to that discussed in A_Basic_Computer#Adding_Binary_Numbers_prelude.
First, watch the video about using the program Logicly: Video.
Next, read [8].
 Create a circuit using http://logic.ly/demo that reproduces Table 2 at [9].
 Label the inputs and outputs appropriately (That is, tell me what a switch in the on or off position in corresponds to in Table 2 [10].
 What does a lit/unlit bulb correspond to in Table 2?.)
 Sketch the diagram that you created or attach a printed version of your logic circuit. (Instructions for printing are given at the end of the Video.
6.3. Activity I
Suppose that you want to have a third light bulb light up only when Sp and Co are on. How would you change the diagram? Hint: You can do this by adding an AND gate and connecting its output to the new bulb. The question is then where to connect the inputs to the new AND gate. If you get it to work, see if you can get the same result using two or more gates and a different wiring configuration.

6.4. Activity II
(Difficult) If you figured out the above problems, try this problem. Suppose that you want to develop a circuit that does this binary addition problem, where A, B, C, and D can be 0 or 1.
A B C D + ________ C3 C2 C1
 How many rows will your logic table need?
 Develop a logic circuit that does the calculation. There should be three light bulbs and four switches.
 Use a LED to show the result of the sum as a decimal number.
