1 00:00:04,190 --> 00:00:09,267 In the previous lesson, you installed Logisim and created half and full adders. 2 00:00:09,598 --> 00:00:14,267 Now it's time to build an ALU or Arithmetic Logic Unit. 3 00:00:14,550 --> 00:00:20,902 To keep things easy-to-follow and straightforward, we'll be building a 4-bit ALU with four operations: 4 00:00:21,168 --> 00:00:25,388 AND, OR, NOT, and addition/subtraction. 5 00:00:25,604 --> 00:00:28,364 The first step is to create a new Logisim file. 6 00:00:28,615 --> 00:00:31,776 Save this file as 4-bit ALU.circ. 7 00:00:32,374 --> 00:00:37,584 Once you have a blank canvas, let's create sub-circuits for the adders, the AND and the OR. 8 00:00:38,385 --> 00:00:45,420 Next, right-click on the main folder (4-bit ALU) and select Add Circuit, as shown in Figure 1: 9 00:00:46,204 --> 00:00:48,176 Name the circuit Full Adder. 10 00:00:48,865 --> 00:00:51,897 Repeat to add the following circuits as mentioned below: 11 00:00:52,395 --> 00:00:57,705 4-bit Adder/Subtractor, 4-bit AND, 4-bit OR 12 00:00:57,824 --> 00:01:01,133 Your Logisim explorer window should look as follows: 13 00:01:01,464 --> 00:01:02,430 Save your work! 14 00:01:03,004 --> 00:01:05,409 Now, let's build the sub-circuits. 15 00:01:06,063 --> 00:01:09,280 The following diagrams show the setup for the adders. 16 00:01:09,394 --> 00:01:12,940 To open the canvas, double-click on the Full Adder circuit. 17 00:01:13,086 --> 00:01:14,523 Add the following: 18 00:01:14,765 --> 00:01:21,806 1 input pin, labeled In, facing South 2 input pins, labeled A and B, facing East 19 00:01:21,996 --> 00:01:25,545 1 output pin, labeled Result, facing West 20 00:01:25,707 --> 00:01:28,887 1 output pin, labeled Out, facing North 21 00:01:29,282 --> 00:01:33,558 2 XOR gates, facing East (2 inputs, 1 data bit) 22 00:01:34,021 --> 00:01:38,952 2 AND gates, facing South (2 inputs, 1 data bit) and 23 00:01:39,080 --> 00:01:43,182 1 OR gate, facing South (2 inputs, 1 data bit) 24 00:01:44,026 --> 00:01:48,003 Arrange and connect them, referring to this next figure appearing here: 25 00:01:49,587 --> 00:01:53,892 The Adder/Subtractor shown in that previous figure might look complicated, 26 00:01:54,036 --> 00:01:58,055 but we will actually be able to add in the adders we created previously. 27 00:01:58,456 --> 00:02:01,650 You can click an element from the explorer menu on the left 28 00:02:01,806 --> 00:02:05,233 (e.g., Full Adder), and drag it onto your canvas. 29 00:02:05,496 --> 00:02:08,962 In the 4-bit Adder/Subtractor circuit, add the following: 30 00:02:09,926 --> 00:02:14,473 Drag and drop 4 of the Full Adders you created earlier onto the canvas 31 00:02:14,603 --> 00:02:17,513 (the will have + signs on them); arrange vertically 32 00:02:18,496 --> 00:02:23,840 An East-facing pin called Add/Subtract Control (add this to the top left) 33 00:02:24,466 --> 00:02:27,762 A North-facing Pin called B, with 4 data bits 34 00:02:27,819 --> 00:02:31,145 A South-facing pin called A, with 4 data bits 35 00:02:31,739 --> 00:02:35,575 4 East-facing XOR gates, each with 2 inputs 36 00:02:36,490 --> 00:02:39,705 3 South-facing NOT gates, each 1 data bit 37 00:02:40,230 --> 00:02:44,774 2 East-facing AND gates, each 1 Data bit and 3 inputs 38 00:02:45,560 --> 00:02:47,746 3 splitters with 4 inputs 39 00:02:48,479 --> 00:02:51,496 Output pins for Carry out and Overflow 40 00:02:51,699 --> 00:02:53,417 Connect All Elements 41 00:02:53,930 --> 00:02:58,330 Next, connect all elements as shown in this next figure appearing here. 42 00:02:58,760 --> 00:03:05,421 This figure, which we'll call figure 3, is the completed 4-bit adder/subtractor will all components. 43 00:03:06,220 --> 00:03:08,517 In this sub-circuit, we add the following: 44 00:03:08,873 --> 00:03:11,923 Two Inputs, A and B, with 4 data bits 45 00:03:12,212 --> 00:03:14,100 Two splitters with 4 bits 46 00:03:14,312 --> 00:03:17,068 4 AND gates with two inputs each 47 00:03:17,176 --> 00:03:20,091 Another splitter with 4 bits and finally, 48 00:03:20,179 --> 00:03:22,997 An output pin, Result with 4 bits 49 00:03:23,521 --> 00:03:27,464 Add elements and connect as shown in this next figure appearing here: 50 00:03:28,345 --> 00:03:36,034 The 4-Bit AND matches the 4-Bit OR subcircuit, except you add 4 AND gates, as shown in this next figure 51 00:03:36,849 --> 00:03:39,236 Now, let's build the final ALU. 52 00:03:40,024 --> 00:03:43,951 We build the circuit it from left to right, showing the final output at the end. 53 00:03:44,393 --> 00:03:47,064 Step 1: Add the Two Input Pins 54 00:03:47,434 --> 00:03:51,861 Drop two East-facing input pins on the canvas 4-bits each. 55 00:03:52,094 --> 00:03:56,379 Label them A and B, and ensure that each input is 4-bits. 56 00:03:56,768 --> 00:04:00,268 Step 2: Add the Adder/Subtractor and Gates 57 00:04:00,544 --> 00:04:03,453 Now we add the sub-circuits created earlier. 58 00:04:03,703 --> 00:04:08,979 Select the circuits under the main project folder, referring to the diagram appearing here now: 59 00:04:09,591 --> 00:04:11,802 Then click on the canvas to drop them. 60 00:04:12,079 --> 00:04:13,762 Drop each of the following: 61 00:04:13,935 --> 00:04:19,304 The 4-Bit Adder/Subtractor The 4-Bit AND and The 4-Bit OR 62 00:04:19,990 --> 00:04:22,516 Step 3: Add the Multiplexers 63 00:04:22,903 --> 00:04:27,409 Recall that an ALU needs multiplexers, or (MUX). 64 00:04:27,678 --> 00:04:31,608 These take on or more data inputs and generate a single output. 65 00:04:31,773 --> 00:04:35,120 In Logisim, multiplexers are under the Plexers folder. 66 00:04:35,354 --> 00:04:39,093 Click the Multiplexer icon and drop two of them onto our canvas. 67 00:04:39,734 --> 00:04:42,639 Each has one Select Bit and 4 Data Bits: 68 00:04:43,493 --> 00:04:45,573 Step 4: Add Controls 69 00:04:46,025 --> 00:04:48,742 Now we need our controls for the multiplexers. 70 00:04:49,080 --> 00:04:53,161 Drop two pins on the canvas, north-facing, with 1 data bit. 71 00:04:53,283 --> 00:04:55,987 Label them 0 and 1, respectively. 72 00:04:56,436 --> 00:04:58,339 Step 5: Add a Splitter 73 00:04:58,646 --> 00:05:02,620 Next, we add a splitter into our circuit that takes one line from the second 74 00:05:02,731 --> 00:05:08,077 multiplexer and split to 4 inputs to an OR gate - for a 4-bit ALU. 75 00:05:09,260 --> 00:05:12,555 Step 6: Add Another OR Gate And a Not Gate 76 00:05:13,326 --> 00:05:17,172 Now we add an OR gate after the splitter, which has 4 inputs 77 00:05:17,444 --> 00:05:20,199 (from the splitter; we'll add the lines later). 78 00:05:20,484 --> 00:05:23,297 To the right of the OR gate, add a NOT gate. 79 00:05:23,884 --> 00:05:28,651 This arrangement accounts for Zero output when ALL of the bits result in zero. 80 00:05:29,013 --> 00:05:31,850 The NOT gate following the OR gate achieves this. 81 00:05:32,524 --> 00:05:36,959 Finally, add a single-bit pin after the NOT gate to store the result. 82 00:05:37,045 --> 00:05:38,318 Label it ZERO. 83 00:05:38,939 --> 00:05:42,153 Step 7: Add a Result Pin for the MUX 84 00:05:42,597 --> 00:05:45,274 We handled the zeroes coming from the MUX, 85 00:05:45,425 --> 00:05:51,572 but we also need to account for valid combinations of inputs from A, B, and the Control inputs. 86 00:05:51,796 --> 00:05:55,066 Add a 4-bit pin to the right of the MUX. 87 00:05:55,164 --> 00:05:56,462 It should be West-facing! 88 00:05:57,133 --> 00:06:01,192 Step 8: Add Negative, Carry, and Overflow Pins 89 00:06:01,267 --> 00:06:02,967 We're almost there! 90 00:06:03,057 --> 00:06:09,225 Let's recall from the ALU design, that when the most significant bit is 1, the final result is negative. 91 00:06:09,572 --> 00:06:15,425 In situations where the result is large enough to not fit into our bit allowance, we get a carry. 92 00:06:16,079 --> 00:06:21,794 Finally, if our signs are mixed up and you get a result of -1, you need a catch for overflow. 93 00:06:22,172 --> 00:06:27,431 Add three more pins for each, below the Zero pin, and allow space to connect them all. 94 00:06:27,952 --> 00:06:30,093 Step 9: Connecting the Circuits 95 00:06:30,487 --> 00:06:32,290 Now it gets interesting. 96 00:06:32,465 --> 00:06:37,176 We need to connect all the parts to finally build our first 4-bit ALU. 97 00:06:37,542 --> 00:06:42,402 Make your connections carefully; remember you can Undo if something goes awry! 98 00:06:42,555 --> 00:06:47,709 You may have to shift some of the components around the canvas; this might make your lines look funny. 99 00:06:47,854 --> 00:06:51,133 There's no harm in deleting and re-adding the lines. 100 00:06:51,314 --> 00:06:55,370 Also, you can click on the middle of any line and start a new one 101 00:06:55,565 --> 00:06:59,572 (see the line from Input A down to the 4-bit Adder as an example). 102 00:07:00,380 --> 00:07:03,646 And finally, Step 10: Perform Final Test! 103 00:07:03,983 --> 00:07:06,087 Now let's test this out! 104 00:07:06,177 --> 00:07:08,493 Click the hand icon in the toolbar. 105 00:07:08,585 --> 00:07:12,215 Try the following, watching the output result pins as you do. 106 00:07:12,938 --> 00:07:17,964 Click the input pin A, selecting individual bits, changing from 1 to 0. 107 00:07:18,185 --> 00:07:19,306 What happens? 108 00:07:19,507 --> 00:07:23,703 And Click the Control inputs 0 and 1 to change values 109 00:07:23,919 --> 00:07:28,473 Note: If you messed up any connections, or didn't set the bit values right, 110 00:07:28,577 --> 00:07:32,145 the lines change their color to red, and you might get errors. 111 00:07:32,348 --> 00:07:36,046 Be sure to check your gates and inputs so that the bits are accurate. 112 00:07:39,538 --> 00:07:42,944 That was a lot, so let's briefly review what we've learned. 113 00:07:43,419 --> 00:07:49,057 In this lesson, we've constructed a 4-bit ALU (or the Arithmetic Logic Unit), 114 00:07:49,709 --> 00:07:53,490 building upon the knowledge gained in designing adders and half-adders. 115 00:07:54,024 --> 00:07:59,000 Using Logisim, we put together each piece, including sub-circuits, control inputs, 116 00:07:59,142 --> 00:08:04,452 and outputs to account for valid values, zero, negative, and overflow output. 117 00:08:04,907 --> 00:08:06,723 After completing this exercise, 118 00:08:06,883 --> 00:08:11,593 you should feel more confident in your ability to design logical circuits in Logisim, 119 00:08:11,740 --> 00:08:14,749 especially if you remember to follow the steps we covered. 120 00:08:15,061 --> 00:08:17,874 For a quick refresher, they included the following: 121 00:08:18,401 --> 00:08:20,685 Step 1: Add the Two Input Pins 122 00:08:21,022 --> 00:08:24,704 Step 2: Add the Adder/Subtractor and Gates 123 00:08:24,960 --> 00:08:27,290 Step 3: Add the Multiplexers 124 00:08:27,465 --> 00:08:29,562 Step 4: Add Controls 125 00:08:29,822 --> 00:08:31,658 Step 5: Add a Splitter 126 00:08:32,070 --> 00:08:35,730 Step 6: Add Another OR Gate And a Not Gate 127 00:08:35,982 --> 00:08:39,396 Step 7: Add a Result Pin for the MUX 128 00:08:39,521 --> 00:08:43,584 Step 8: Add Negative, Carry, and Overflow Pins 129 00:08:43,641 --> 00:08:45,558 Step 9: Connecting the Circuits 130 00:08:45,700 --> 00:08:49,064 And finally, Step 10: Perform Final Test!