Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439

In this lab, you will use thetool, along with pen and paper, to analyse and create simplecombinatorial circuits.

Installing and Starting Logisim

Unlike Snap!, Logisim does not run in a web browser but needsto be installed. It is not installed on the CSIT lab computers,so to use it, you will have to install it on your own computeror on your student account.

  1. Download and save it in a convenient location(e.g., your home directory).

  2. You will probably be able to start the program by simply(double-)clicking on the JAR file.If that doesn’t work, on a GNU/Linux system you can start acommandline (“terminal”) and type in

    java -jar logisim-generic-2.7.1.jar

    (assuming you are in the directory where the file is).

    Note that Logisim requires Java version 5 or later.

Exercise 9.1 (no marks)

First, do the following simple exercise to familiarise yourself abit with the Logisim environment.

  1. Download the file (using “save link as”), then open the file in Logisim(select “Open…” under the “File” menu).If everything worked, you should now see a simple combinatorialcircuit.

  2. What does this circuit do? It computes some function

    Output = F(A, B, C)

    where all three inputs and the output are binary (0 or 1).But what is the function F? To find out, you can:

    a. Figure it out by looking at the circuit.

    b. Select the “poke” tool(),click on the inputs A, B and C to change their value, and observehow the output changes.

    c. From the “Project” menu, select “Analyze Circuit”.This opens a window with information about the circuit.Under “Table” you can find the complete truth table for thecircuit, and under “Expression” you can see the equivalentBoolean expression.(Note that Logisim does not have a symbol for logical AND inexpressions: “x AND y” is written just “x y”. The symbol forlogical OR is “+” and for NOT is “~“.)

    Make sure you try the first two methods before the last.

  3. Is there a simpler/smaller circuit that computes the same function?Using the truth table for the circuit, attempt to find a smallerexpression that generates the same table. Build the corresponding circuitnext to the one given (using the same inputs, but a new output) and testit to see that it gives the same result.

(Again, Logisim offers you a way to cheat: The “Minimized” tab of thecircuit analysis window will give you a minimal expression, and caneven rebuild the circuit automatically for you. Use this to check whatyou came up with by hand.)

Exercise 9.2 Sorting Numbers with Circuits

In this exercise, you will construct a circuit that sorts four4-bit binary numbers. This means the circuit has has 16 inputsand 16 outputs! If you tried build it directly, the result wouldprobably be pretty gigantic.So, instead, we will introduce some intermediate abstractions,which will help keep the size of the result manageable.

Download the file and open it inLogisim.The project contains several defined components: a “1-bit swap”,a “4-bit swap” and a “4-bit compare & swap”.

Task 1 1-bit swap (50%)

The 1-bit swap element is not implemented. Your first task is to build it.

The 1-bit swap has three inputs, called Input 1, Input 2 andswap?, and two outputs, called Output 1 and Output 2.The element is meant to implement a controllable swap of the twoinputs into the two outputs.In other words, behaviour of the circuit should be as follows:

Hints

To help you understand how to make this work, you can draw up thetruth table (it has only 23 = 8 lines) and fill in thecorrect outputs for each case.

If you are using more than 10 gates to build the circuit, you’re on thewrong track; there is an easier solution. Look at the truth table.

All the inputs and output that your circuit should have are alreadyin place, so you should not have to place any new “pins”.

How to build circuits in Logisim

Here is showing how it isdone. (Note: The circuit built in the video is not the solution tothis exercise!)

Test your circuit!

After you have built a circuit, you can check that it does the rightthing by either using the poke tool to vary the inputs, or usingLogisim’s built-in circuit analyzer, which will show you the truthtable for both outputs.

The 4-bit swap element is implemented using several 1-bit swaps. Thus,after you have built the 1-bit swap (correctly), the 4-bit swap willalso work. In the main circuit, off to the right, there is a small testcircuit for the 4-bit swap: it has two 4-bit inputs and a (1-bit) swapinput, and two displayed outputs. Using the poke tool, you can changethe inputs; when you toggle the swap bit, you should see the outputschange place. (Note that when you use the poke tool to change multi-bitinputs, you must toggle each bit separately by clicking on it.)

Task 2 The 4-number sorting circuit (50%)

The 4-bit compare & swap element has two inputs and two outputs, whichare all 4-bit binary numbers. It sorts the two input numbers: that is,the first (upper) output is the smaller of the two numbers, and thesecond (lower) output is the bigger one. Note that it does an unsignedcomparison. This means the numbers are interpreted as positive (rangingfrom 0 to 15), not in 2’s complement.

The 4-bit compare & swap element is implemented using the 4-bit swapand a “comparator” (a component from Logisim’s standard library).A test circuit is provided (also to the right in “main”): use the poketool to change the inputs and observe what happens with the output.(This is also a chance to practice reading binary numbers: how do youset the inputs to, for example, 12 and 9?)

Now, you should build the 4-number sorting circuit using only 4-bitcompare and swap elements (and wires). The inputs (labelled A-D) areon the left and the outputs (labelled #1-#4) are on the right. Theoutputs should be the inputs sorted in increasing order, that is,#1 should be the smallest of A,B,C,D, #2 the second smallest, and soon.

Hint

If you have trouble working out how to sort the four numbers, thinkrecursively. This circuit gives you part of one possible solution forsorting three numbers:

After the two compare & swaps, the top wire has the smallest number, andthe other two hold the two larger numbers (but not in sorted order). Howwould you complete this circuit to sort all three numbers?If you have a circuit that can sort three numbers, how could you use itto sort four numbers?

Test and save your circuit!

After you have built the circuit, check that works by varying the inputs.(The circuit analyzer tool does not work with multi-bit inputs and outputs.)

Save your circuit in a new file (using “Save As…” from the File menu).This is the file that you will need to submit for this assignment.

Submission:

You must submit one Logisim circuit file, containing your solutionsto Tasks 1 and 2. Submit the files through.

1 May, 2016
1410 words


Written by
Tags

Quick links

2016 S1 lectures :

Note: TBD.

Quick-access class pointers: TBC