CPSC 120: Principles of Computer Science,Spring 2002

Lab 2: Logic Circuits, Part 1


FOR THIS LAB, you should read the material in xLogicCircuits Lab 1, which you can find at:

http://math.hws.edu/TMCM/java/labs/xLogicCircuitsLab1.html

or just go the the CS120 web page and click on the appropriate link.

You should run the xLogicCircuits applet that can be found on that page, and you should practice using it to create and test some logic circuits. However, you should do the exercises on this page and turn them in next Wednesday in class. Two of the exercises ask you to create logic circuits and save them in your Linux account. Unfortunately, it is not possible to save or load files of information from an applet that is running off a Web page. You have to somehow run the applet as an independent application. The information on this page tells you two ways to do this.


Accessing your Linux Account from Windows

The wonderful world of networked computers makes it possible to sit at one computer and access resources that are on another computer. (Of course, with the World Wide Web, this has become very commonplace, but it's still quite an achievement.) You have already seen how you can sign on to your Linux account from Windows using X-Win32. However, it is also possible to access the information in your account and use it directly under Windows without logging on to Linux.

You should already be signed onto the Windows network. To make your the files in your Linux account available on the Windows computer, follow these steps:

You can then use the files in your Linux account from Windows programs, in exactly the same way that you use other files under Windows. In particular, you will be able to save files into your Linux account.

To run the applets outside of a browser under windows, do the following: Open the "My Computer" icon (by double-clicking it), then open the "PCcommon" icon, and inside that find and open the "cpsc120" icon. In the directory window for cpsc120, you will find two program icons: "RunTuts.bat" and "RunLabs.bat". (They might be named simply "RunTuts" and "RunLabs".) You can use either one of these program to run the applets independently of a browser. When you double-click on one of these icons, you will see a small window full of buttons. Click on the appropriate button to run the applet that you want. The difference between "RunTuts.bat" and "RunLabs.bat" is that in "RunLabs.bat", the applets are loaded with the examples from the lab worksheets. For example, if you run "RunLabs.bat" and click on the button labeled "xLogicCircuts Lab 1", you will see the xLogicCircuits applet with all the examples from xLogicCircuits Lab 1.

When you use the applets through "RunTuts.bat" and "RunLabs.bat", you will be able to save your work in files and load files that have been saved previously. To save a file in xLogicCircuits, for example, click the "Save" button at the top of the applet. You will get the usual file-save dialog box that you can use to name the file and navigate to the directory where you want to save it. In the exercises below, I want you to save the files in the homework directory in your Linux account.


Running the Applets in your Linux Account

In addition to running the applets under Windows, you can run them directly in your Linux account when you are logged into that account. Just open the Konqueror (by clicking on the Home Directory icon at the bottom of the screen, for example). Enter /home/cs120 in the "Location" box, and press return. You will see programs named "RunTuts" and "RunLabs". You can click -- once -- on either of these programs to run the applets. (Tip: If you want to make things even easier, click-and-drag either program onto your Linux desktop. When a pop-up meu appears, select "Link Here". A "link" icon for the program will be added to your desktop. Clicking the icon will run the program, so you won't have to open a directory window to run it.)

You can save and load files when running the applets under Linux. If you use the "RunTuts" program, you will find that it is set up to go to the "homework" directory in your home directory. This will be convenient when you want to save the work that you do for lab exercises.

Note: Files that you want to turn in as part of your lab reports should be in the homework directory in your Linux account. If you want to organize that directory, you might make sub-directories inside that directory. To make a new Directory, go to the "Edit" menu of the Konqueror window. Point to the "Create New" item in this menu. A sub-menu appears. Select "Directory" from this submenu. You will be asked to enter a name for the directory. You can also access the "Create New" menu by right-clicking in a directory window. You can do something similar by right-clicking on a directory window under Windows.


Exercises (to be Done for February 30)


Exercise 1: Given a logical expression, it's possible to build a logic circuit that computes the value of that expression. Use xLogicCircuits to build three logic circuits that compute the values of the following expressions:

            (A and B) or (B and C)
            (not (A and B)) and (A or B)
            (A or B or C) and not (A and B and C)

Save your results in one or more files in your homework directory. You can either build all the circuits on one screen and save the results in one file, or you can build the circuits on several screens and save them in several files. In the lab report that you hand in, tell me the name of any file that you create. (If you are working with a partner, don't forget to tell me whose account I should look in to find your work.)


Exercise 2: Given a logic circuit, it's possible to find a logical expression that describes the output of the circuit (at least as long as the circuit does not contain any feedback loops). Do this for each of the following circuits. That is, find a Boolean algebra expression that describes the output of each circuit in terms of its inputs.




Exercise 3: Write a short essay describing a procedure that can be applied to solve problems like the ones in the previous exercise. That is, given a logic circuit with one output and without feedback loops, how can someone go about finding the logical expression that describes the output of the expression in terms of its inputs? Also, explain what goes wrong when you try to apply your procedure to a circuit that contains a feedback loop.


Exercise 4: Another way to specify a circuit is with an input/output table. As explained in the textbook, the table can be used as a guide for writing a logical expression that describes the circuit. Then the expression can be used as a blueprint for the circuit. Consider the following input/output table, which describes the desired behavior of a three-input circuit:

ABCOutput
ON ON ONOFF
ON ONOFFON
ONOFF ONOFF
ONOFFOFFOFF
OFF ON ONON
OFF ONOFFOFF
OFFOFF ONOFF
OFFOFFOFFOFF

Use xLogicCircuits to build a circuit that has the specified input/output behavior. Note that your circuit must work for all possible combinations of inputs. Save the circuit in a file in your homework directory.


Exercise 5: One of the examples in the lab was a circuit called "Two or More", which checks whether at least two of its three inputs are on. Consider the problem of finding a similar circuit with four inputs. The output should be on if any two (or more) of the four inputs are on. A circuit that does this can be described by the Boolean expression:

(A and (B or C or D)) or (B and (C or D)) or (C and D)

Use this expression to construct a "Two or More" circuit with four inputs. Try to understand where this expression comes from. Why does it make sense? (Hint: Think of two cases, one case where the input A is ON, and the other case where the input A is OFF.) Write a paragraph explaining this. The form of this expression can be extended to handle circuits with any number of inputs. Also, write down a logical expression that describes a circuit with five inputs that turns on its output whenever two or more of the inputs are on.

Turn in your paragraph, the logical expression for the five-input circuit, and a drawing of the four-input circuit. Instead of making the drawing, you can, if you prefer, construct the four-input circuit using xLogicCircuits and save it in a file in your homework directory. (If you do this, please make sure that your lab report tells me where to find the file.)


--David Eck (eck@hws.edu), January 2002