CS 10, Spring 1998

Homework 5

Due: Thursday, April 2


Homework Description

For this homework, you will use DigSim to build a simple programmable circuit. Your circuit will take as input two binary numbers, each two bits long. Let's refer to the two input numbers as a and b. Then a will be represented by two input switches (one wire for each digit of a), and similarly, b will be represented by two input switches. Your circuit will have a single output. Your circuit should be able to perform each of the following operations, depending on how it is programmed:

  1. It should be able to determine whether the two inputs are equal. In this case, the output should be 1 if the two inputs are equal, and 0 otherwise.

  2. It should be able to determine whether two outputs aren't equal. In this case, the output should be 1 if the two inputs aren't equal, and 0 otherwise.

  3. It should be able to determine whether input a is greater than input b. In this case, if a is greater than b, the output should be 1; if not, the output should be 0.

  4. It should be able to determine whether input a is greater than or equal to input b. In this case, if a is greater than or equal to b, then the output should be 1; the output should be 0 otherwise.
In addition to the 4 input switches which represent the inputs a and b, your circuit should have two more switches, which allow it to be programmed. So depending on how these two switches are set, the output will be the result of either operation 1, operation 2, operation 3, or operation 4 above.

Begin by building each of the following subcircuits:

  1. First build a four-way MUX. A diagram of this circuit is shown below. Note that this will be easier to build if you use the 3-way AND gate and 4-way OR gate which you built for lab 6.1 (if you don't have these anymore, you can get them from the "6.1 solutions" folder in the module 6 folder on the classes server). In the diagram below, the settings of inputs C1 and C2 determine which of the four inputs I1, I2, I3, or I4 will be the output. For example, if both C1 and C2 are 1, then the output will be whatever the value of I4 is. If both C1 is 1 and C2 is 0, then the output will be whatever the value of input I3 is.

    Once you've built this circuit, you can save it and then use it later as a sub-circuit. After you've built the circuits to perform each of the 4 operations above (i.e., the circuits that test whether a = b, whether a is not equal to b, whether a > b, and whether a >= b), you can hook the outputs of these circuits to the inputs I1 - I4 of the MUX, and then set the switches C1 and C2 to determine which of the four above operations will be sent to the output wire.

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

  2. Next, build a two-bit comparator. This circuit will perform operation 1 above. That is, it will take as input 2 numbers a and b, each of which are two bits long, and will have one output, which will be 1 if a = b, and 0 otherwise. When you've finished, save this circuit as a subcircuit.

    Hint: In lab 6.1, you built a 1-bit comparator which tests whether two inputs, each a single bit long, are equal. (If you don't have this circuit anymore, you can get a copy of it from the "6.1 solutions" folder in the module 6 folder on the classes server). Use this 1-bit comparator as a subcircuit in the two-bit comparator. Since a is two bits long, it is represented by two input wires, say A1 and A2. Similarly, b will be represented by two input wires, say B1 and B2. Now a = b only in the case when both A1 = B1 and A2 = B2. You can use 1-bit comparators to test whether A1 = B1 and whether A2 = B2

  3. After this, use the two-bit comparator to build a circuit which performs the opposite operation (operation 2, above). In this case, the output should be 1 if a and b aren't equal, and 0 otherwise. (Once you've built the two-bit comparator, you should be able to build this circuit in 30 seconds.) When you've finished, save this circuit so that you can use it later as a subcircuit.

  4. The next circuit you need to build should test whether input a is greater than input b.

    One way to get started is to first build a circuit which takes two inputs, P and Q, and has 1 output which is 1 only in the case where P > Q. That is, the output will be 1 only in the case where P = 1 and Q = 0.

    Once you have this circuit, you can use it, along with the 1-bit comparator from lab 6.1, to determine whether input a is greater than input b. Since inputs a and b are both two bits long, they will each be represented by two input wires. Let's call these wires A1, A0, B1, and B0, where a = A1A0 and b = B1B0. Now a is greater than b when either

    When you've finished building this circuit, save it so that you can use it as a subcircuit later.

  5. Once you have the circuit above, which tests whether a > b, as well as the circuit which tests whether a = b, it should then take you 30 seconds to build a circuit which performs operation 4-- that is, that outputs 1 when a is greater than or equal to b. Save this circuit so that you can use it later as a subcircuit.

When you've built and saved each of the above subcircuits, as well as the 4-way MUX, then your final job is to connect these circuits together into one circuit that performs each of the four operations above, and which uses the 4-way MUX to select which of the four operations the output will represent. This final circuit should have 1 output, and 6 input switches-- 2 input switches which represent the number a, two input switches which represent the number b, and 2 input switches which set the MUX. The two switches which set the MUX are used to determine which of the four operations that are performed will be sent to the output. So in setting these two switches, you're programming your circuit to perform either a test for equality, a test for inequality, a test for greater than, or a test for greater than or equal to.