A Basic Computer

From CDS 130

Jump to: navigation, search

A Basic Computer

Contents

  1. Objectives
  2. Motivation
  3. Priming questions
  4. Notes
    1. Motivation
    2. Adding Binary Numbers prelude
    3. Adding Binary Numbers prelude
    4. Adding Binary Numbers
    5. To add any binary numbers
    6. 1-bit adder
  5. Questions
    1. Decision table
    2. Bird brain
    3. NOR gate using NANDs
    4. OR gate with NANDs
  6. Activities
    1. logic.ly
      1. logic.ly introduction
      2. Using logic.ly
    2. Bird brain
    3. Activity I
    4. Activity II

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

  • A mechanical robot [1]
  • A mechanical clock that illustrates how a CPU works [2]

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
    1. learned some of the basic tools (binary numbers, binary addition, bit patterns)
    2. learned some of the parts in a computer (transistors, logic gates)
    3. built a simple computer using these parts (will do that today)
    4. 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.
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
Corresponds to top row in table
Corresponds to top row in table
Corresponds to bottom row in table
Corresponds to bottom row in table

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
  • Above is the most complex operation that you will ever need to do when adding two binary numbers (did this in the second column of the problem to the left):
    • Ci = Carry in
    • Co = Carry out
    • Sp = Sum part
  • If we can figure out how to do this, we can figure out how to add any two binary numbers.

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.

A B Ci Sp Co
0 0 0 0 0
0 1 0 1 0
1 0 0 1 0
0 0 1 1 0
1 1 0 0 1
0 1 1 0 1
1 0 1 0 1
1 1 1 1 1
 
    Co Ci  
        B
  +     A
       __
        Sp

4.6. 1-bit 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 1-bit 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 8-bit numbers.

A B Ci Sp Co
0 0 0 0 0
0 1 0 1 0
1 0 0 1 0
0 0 1 1 0
1 1 0 0 1
0 1 1 0 1
1 0 1 0 1
1 1 1 1 1

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/un-lit 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/un-lit 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.

Image:NOR_LOGIC_GATE.svg
Logic table for NOR gate
Input A Input B Output
0 0 1
0 1 0
1 0 0
1 1 0

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.

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:

  • A zero for inputs A or B is represented by them being in the "off" position in the diagram.
  • A zero for the output is represented by the light bulb being off in the diagram.

AND logic table

Input A Input B Output
0 0 0
0 1 0
1 0 0
1 1 1

Image:andoptions2.png

6.1.2. Using logic.ly

  1. 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.
  2. 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).
  3. Verify that the table for the 1-bit adder is correct by selecting the one-bit 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].

  1. Create a circuit using http://logic.ly/demo that reproduces Table 2 at [9].
  2. 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].
  3. What does a lit/un-lit bulb correspond to in Table 2?.)
  4. 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.

A B Ci Sp Co
0 0 0 0 0
0 1 0 1 0
1 0 0 1 0
0 0 1 1 0
1 1 0 0 1
0 1 1 0 1
1 0 1 0 1
1 1 1 1 1

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.
A B C D C3 C2 C1
0 0 0 0 0 0 0
Personal tools