What you will build
Four circuits, each checked with a test vector: a half adder, a full adder, a 4-bit ripple-carry adder and a 4-bit adder-subtractor. They use AND, OR, XOR gates, pins, splitters and subcircuits. Plan on about two hours. Every circuit is a download, so you can compare yours with ours.
Before you start
Use Logisim-evolution 5.0.0. Classic 2.7.1 files are offered for the half adder, the full adder and the 4-bit adder because some courses still require 2.7.1 (which version?). Give every pin a Label, and keep the labels on this page: A, B, Cin, S, Cout. If you are new to the window, do the tutorial first.
Half adder in Logisim
| # | A | B | S | C |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | |
| 0 | 1 | 1 | 0 | |
| 1 | 0 | 1 | 0 | |
| 1 | 1 | 0 | 1 |
Place two input pins
Use the Input pin tool and label the pinsAandB.Check: Pins A and B are on the canvas.
Place an XOR gate and an AND gate
From the toolbar. Two inputs is the default in 5.0.0 (gates).Check: Both gates have two inputs.
Place two output pins
Label themSandC.Check: Pins S and C are on the canvas.
Wire it
A and B each go to both gates; XOR to S and AND to C.Check: Every pin is joined.
Poke and compare
Use the Poke tool on A and B.Check: All four rows match the table.
Describe this circuit
Components: Input pin A; Input pin B; XOR Gate 1; AND Gate 1; Output pin S; Output pin C.
- Input pin A connects to XOR Gate 1, AND Gate 1 (net A).
- Input pin B connects to XOR Gate 1, AND Gate 1 (net B).
- XOR Gate 1 connects to Output pin S (net S).
- AND Gate 1 connects to Output pin C (net C).
Download the half adder or its 2.7.1 version. Project, Analyze Circuit shows the table Logisim derives from your circuit; see the tutorial and Combinational Analysis.
Full adder in Logisim
| # | A | B | Cin | S | Cout |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 1 | 1 | 0 | |
| 0 | 1 | 0 | 1 | 0 | |
| 0 | 1 | 1 | 0 | 1 | |
| 1 | 0 | 0 | 1 | 0 | |
| 1 | 0 | 1 | 0 | 1 | |
| 1 | 1 | 0 | 0 | 1 | |
| 1 | 1 | 1 | 1 | 1 |
The second form of Cout reuses the first XOR: A ⊕ B is already computed for the sum.
Two half adders and an OR gate
Build the full adder as two half adders and an OR gate. The first half adder takes A and B. The second takes its sum and Cin. The OR gate combines the two carries. Our file draws it with gates directly:
Describe this circuit
Components: Input pin A; Input pin B; Input pin Cin; XOR Gate 1; AND Gate 1; XOR Gate 2; AND Gate 2; OR Gate 1; Output pin S; Output pin Cout.
- Input pin A connects to XOR Gate 1, AND Gate 1 (net A).
- Input pin B connects to XOR Gate 1, AND Gate 1 (net B).
- Input pin Cin connects to XOR Gate 2, AND Gate 2 (net Cin).
- XOR Gate 1 connects to XOR Gate 2, AND Gate 2.
- AND Gate 1 connects to OR Gate 1.
- XOR Gate 2 connects to Output pin S (net S).
- AND Gate 2 connects to OR Gate 1.
- OR Gate 1 connects to Output pin Cout (net Cout).
Download the full adder, its 2.7.1 version and the 8-row vector. To make it a subcircuit for the next step, see Subcircuits. We did not build the multiplexer-based and Combinational Analysis versions.
4-bit ripple-carry adder
How the carry ripples
Four full adders FA0 to FA3: FA0’s carry in is Cin, each carry out feeds the next carry in, and the last carry out is Cout. Bit 0 is the least significant bit. Each stage waits for the carry of the one before it, which is why this design is slow for wide adders.
Splitting buses into bits
A and B are 4-bit pins. A splitter with Fan Out 4 and Bit Width In 4 gives four wires per bus. With the default mapping the first end is bit 0 (F11, Splitter).
Describe this circuit
Components: Input pin A; Splitter 1; Input pin B; Splitter 2; Input pin Cin; fa fa0; fa fa1; fa fa2; fa fa3; Splitter 3; Output pin S; Output pin Cout.
- Input pin A connects to Splitter 1 (net A), 4 bits wide.
- Splitter 1 connects to fa fa0 (net A0).
- Splitter 1 connects to fa fa1 (net A1).
- Splitter 1 connects to fa fa2 (net A2).
- Splitter 1 connects to fa fa3 (net A3).
- Input pin B connects to Splitter 2 (net B), 4 bits wide.
- Splitter 2 connects to fa fa0 (net B0).
- Splitter 2 connects to fa fa1 (net B1).
- Splitter 2 connects to fa fa2 (net B2).
- Splitter 2 connects to fa fa3 (net B3).
- Input pin Cin connects to fa fa0 (net Cin, c0).
- fa fa0 connects to Splitter 3 (net s0).
- fa fa0 connects to fa fa1 (net c1).
- fa fa1 connects to Splitter 3 (net s1).
- fa fa1 connects to fa fa2 (net c2).
- fa fa2 connects to Splitter 3 (net s2).
- fa fa2 connects to fa fa3 (net c3).
- fa fa3 connects to Splitter 3 (net s3).
- fa fa3 connects to Output pin Cout (net c4, Cout).
- Splitter 3 connects to Output pin S (net S), 4 bits wide.
Test it
Load the 512-row vector with Simulate, Test Vector and expect Passed: 512. From the command line:
java -jar logisim-evolution-5.0.0-all.jar --no-splash -w main circ-full-adder-ripple-4bit.vec.txt circ-full-adder-ripple-4bit.circ
A failing run still exits with code 0, so a script must read the text for Failed: 0 (F17). The option needs a display (F18). Download the 4-bit adder or its 2.7.1 version.
| # | A | B | Cin | S | Cout |
|---|---|---|---|---|---|
| 0x0 | 0x0 | 0 | 0x0 | 0 | |
| 0x0 | 0x0 | 1 | 0x1 | 0 | |
| 0x0 | 0x1 | 0 | 0x1 | 0 | |
| 0x0 | 0x1 | 1 | 0x2 | 0 | |
| 0x0 | 0x2 | 0 | 0x2 | 0 | |
| 0x0 | 0x2 | 1 | 0x3 | 0 | |
| 0x0 | 0x3 | 0 | 0x3 | 0 | |
| 0x0 | 0x3 | 1 | 0x4 | 0 | |
| 0x0 | 0x4 | 0 | 0x4 | 0 | |
| 0x0 | 0x4 | 1 | 0x5 | 0 | |
| 0x0 | 0x5 | 0 | 0x5 | 0 | |
| 0x0 | 0x5 | 1 | 0x6 | 0 | |
| 0x0 | 0x6 | 0 | 0x6 | 0 | |
| 0x0 | 0x6 | 1 | 0x7 | 0 | |
| 0x0 | 0x7 | 0 | 0x7 | 0 | |
| 0x0 | 0x7 | 1 | 0x8 | 0 |
Adder-subtractor
To subtract, add the two’s complement: invert B and add 1. XOR each B bit with a SUB signal, and use SUB as the first carry in. SUB = 0 adds; SUB = 1 subtracts.
Describe this circuit
Components: Input pin A; Splitter 1; Input pin B; Splitter 2; Input pin SUB; XOR Gate 1; fa fa0; XOR Gate 2; fa fa1; XOR Gate 3; fa fa2; XOR Gate 4; fa fa3; Splitter 3; Output pin S; Output pin Cout.
- Input pin A connects to Splitter 1 (net A), 4 bits wide.
- Splitter 1 connects to fa fa0 (net A0).
- Splitter 1 connects to fa fa1 (net A1).
- Splitter 1 connects to fa fa2 (net A2).
- Splitter 1 connects to fa fa3 (net A3).
- Input pin B connects to Splitter 2 (net B), 4 bits wide.
- Splitter 2 connects to XOR Gate 1 (net B0).
- Splitter 2 connects to XOR Gate 2 (net B1).
- Splitter 2 connects to XOR Gate 3 (net B2).
- Splitter 2 connects to XOR Gate 4 (net B3).
- Input pin SUB connects to XOR Gate 1, fa fa0, XOR Gate 2, XOR Gate 3, XOR Gate 4 (net SUB, sub, c0).
- XOR Gate 1 connects to fa fa0 (net bb0).
- fa fa0 connects to Splitter 3 (net s0).
- fa fa0 connects to fa fa1 (net c1).
- XOR Gate 2 connects to fa fa1 (net bb1).
- fa fa1 connects to Splitter 3 (net s1).
- fa fa1 connects to fa fa2 (net c2).
- XOR Gate 3 connects to fa fa2 (net bb2).
- fa fa2 connects to Splitter 3 (net s2).
- fa fa2 connects to fa fa3 (net c3).
- XOR Gate 4 connects to fa fa3 (net bb3).
- fa fa3 connects to Splitter 3 (net s3).
- fa fa3 connects to Output pin Cout (net c4, Cout).
- Splitter 3 connects to Output pin S (net S), 4 bits wide.
| # | A | B | SUB | S | Cout |
|---|---|---|---|---|---|
| 0x0 | 0x0 | 1 | 0x0 | 1 | |
| 0x0 | 0x1 | 1 | 0xf | 0 | |
| 0x0 | 0x2 | 1 | 0xe | 0 | |
| 0x0 | 0x3 | 1 | 0xd | 0 | |
| 0x0 | 0x4 | 1 | 0xc | 0 | |
| 0x0 | 0x5 | 1 | 0xb | 0 | |
| 0x0 | 0x6 | 1 | 0xa | 0 | |
| 0x0 | 0x7 | 1 | 0x9 | 0 | |
| 0x0 | 0x8 | 1 | 0x8 | 0 | |
| 0x0 | 0x9 | 1 | 0x7 | 0 | |
| 0x0 | 0xa | 1 | 0x6 | 0 | |
| 0x0 | 0xb | 1 | 0x5 | 0 |
Download circ-adder-subtractor-4bit.circ.
Check yourself
To see what is inside these files, read the .circ file page. Next: an ALU.