Video of the day
This is my favorite Facebook video of all time: click click
Goals
You will be learning how to use the second tier of essential parts of logisim. In particular...
- Splitters to take slices of bits on a wire, and to rejoin them
- Tunnels to avoid 63948732m-long wires
- And you'll also be making a mini ALU
Official Logisim Stuff
Refer to the Logisim Website or last lab for a refresher on Logisim. This website also has documentation on how all the circuit components in the libraries (left-hand side menu) work, so if you're ever unsure of whether something could be helpful for your circuit, consult our good friend cburch.
Setup
Start all Logisim circuits from scratch. Feel free to do each exercise as separate sub-circuits in the same Logisim file.
Copy the lab files from the instructional servers to your lab account with
$ cp -r ~cs61c/labs/07/ ~/labs/07/
Alternatively, secure-copy (scp) them from the instructional servers to your own laptop with
$ scp -r cs61c-xxx@hive10.cs.berkeley.edu:~cs61c/labs/07/ ~/YOUR_FILEPATH
And if you want to secure-copy them back to your class account:
$ scp -r ~/YOUR_FILEPATH/07 cs61c-xxx@hive10.cs.berkeley.edu:~/YOUR_LABACCT_FILEPATH
Exercises
The following exercises will introduce you to more advanced techniques you can use in Logisim.
Exercise 1: Splitters
This is the last essential tool you will need in this class. The preceding sentence was left in the lab specifications by some person from last semester. It's false. You definitely need some more stuff... like tunnels! To demonstrate its use you will construct a circuit that manipulates an 8-bit number.
Open up the logic simulator program called "Logisim" by typing logisim from the terminal. Or by running it however you like to run it.
- Create a new subcircuit and name it "A new subcircuit".
- Add an 8-bit input pin to your circuit and label it.
- Add a 1-bit output pin labeled "Out1" and an 8-bit output pin labeled "Out2" to your circuit.
- Go to the Wiring folder and select the Splitter circuit. This circuit will take a wire and split it into a smaller set of wires. You can do it the other way around too. It can take many sets of wires and combine them into a larger bus.
- Before you place your circuit, change the "Bit Width In" property (bus width) to 8, and "Fan Out" property (# of branches) to 3. If you move your cursor over the schematic, your cursor should look as follows:
- Now, select which bits to send out to which part of your fan. The least significant bit is bit 0 and the most significant bit is bit 7.
- Task: Change bits 1, 2, and 6 to be coming out on fan arm 1 (the middle one).
- Also, make sure bit 0 is coming out of fan arm 0, and bit 7 is still coming out of fan arm 2.
- NOTICE that you have to choose the fan arm for each individual bit. NOT the other way around. You can't choose the bits per arm. Kind of annoying if you have a large bit width in.
- FYI: the "None" option means that the selected bit will not come out on ANY of the fan arms.
- Once you configure your splitter, you can place your splitter into your circuit. Hook your input up to it.
- Attach a 2-input AND gate to fan arms 0 and 2 and route the output of the AND gate to Out1.
- Now we want Out2 to be the negative "sign and magnitude" value of the input. AKA you should interpret the input as a sign and magnitude number. Sign and magnitude is an alternate way of representing signed values - like 2s complement, but simpler! How do you negate a number a sign and magnitude format? Did you say, "flip its 0th bit?" WRONG.
- We will need another splitter to recombine the fans into a single 8-bit bus. Place another splitter with the proper properties (Bit Width In: 8, Fan Out: 3, correct fan widths). Play with the Facing and Appearance properties to make your final circuit as clean-looking as possible.
Sanity check: the second splitter you placed should be facing the opposite direction as the first splitter.
Checkoff [1/3]
- Show your new circuit to your TA.
- Assuming 2's complement representation, what kind of input number (describe it in two adjectives) will produce Out1 = 1?
Exercise 2: Rotate Right
With your knowledge of splitters and your knowledge and experience with multiplexers from the last lab, you are ready to implement a non-trivial combinational logic block: rotr
, which stands for "ROTate Right". Not "rotor." The idea is that rotr A,B
will "rotate" the bit pattern of input A to the right by B bits. So, if A were 0b1011010101110011 and B were 0b0101 (5 in decimal), the output of the block would be 0b1001110110101011. Notice that the rightmost 5 bits were rotated off the right end of the value and back onto the left end.
You must implement a subcircuit named "rotr" with the following inputs:
- A, 16 bits, the input to be rotated
- B, 4 bits, the rotation amount (Why 4 bits?)
- The output should be A rotated right by B bit positions, as outlined above.
- Taking your rights away: You are NOT allowed to use Logisim shifters in your solution, though all other combinational logic (MUXes, constants, gates, adders, etc.) is allowed.
Hint: Before you start wiring, you should think veeeery carefully about how you might decompose this problem into smaller ones and join them together. You should feel very free to use subcircuits when implementing rotr
. If you don't, expect to regret it.
Believe it or not, the preceding snarky paragraph was NOT written by me. Looks like I have some competition from last semester... I wonder who it was. Anyways, it has some good advice.
Hint, the second: Just because we gave you an RTL representation doesn't mean it's the best way to look at this problem. Think about the individual input bits of B (the rotation amount). What can you do with them if you split B with a splitter? Can you do something with the binary form, like with the envelopes in exercise 5 of lab0?
If I want to rotate by 7 = 0b0111, I can rotate once by ___, once by ____, and once by ____
Tip: if you're making some helper subcircuits, think about what you want them to do in your rotr circuit. You'll want to be able to use them as a black box, so make sure they have the correct input and output bit widths.
Tip: To rotate by a fixed amount, you should only require TWO splitters!
Tip: If you've made some helper circuits and are wondering how to combine them, try running the 16-bit input A through a series of MUXes where each MUX decides to either do something or do nothing. Where should their control signals come from?
Checkoff [2/3]
- Show your TA your rotr circuit and verify that it works.