Useful Component in Logisim for the Simulation

I/O

To input or get the output from the circuit, we need to have I/O, and Logisim provides a component called Pin. It has some properties, for example, the Output? property will change the pin between the input mod and the output mod, and the Data Bits property can give us an easy way to input/output multiple bits.

But since one wire can only contain one bit 1/0, when we want to get multiple bits from a pin, we need another component called Splitter. Similar to pin, the splitter also has properties to control the behavior.

The picture below shows how to get the 8-bit input and then output it in reverse using Pin and Splitter. (The trick is I reversed the bit sequence for the output splitter.)

pinandsplitter

The picture above is from Export Image function in Logisim, and the picture below is from a direct screenshot. In the following report, I may only paste one of them.

Gates

Logisim provides some logic gates, for me, the most useful gates are not, and, or, xor.

Not Gate

One input and one output, truth table:

ANot A
TF
FT

And Gate

Two inputs and one output, truth table:

ABA and B
TTT
TFF
FTF
FFF

Or Gate

Two inputs and one output, truth table:

ABA or B
TTT
TFT
FTT
FFF

Xor Gate

Two inputs and one output, truth table:

ABA xor B
TTF
TFT
FTT
FFF

The other gate can easily be obtained by combining some of the gates above, e.g., the NAND Gate is an AND Gate with a NOT Gate.

1-Bit Full Adder

Half Adder

Before getting the full adder, let’s only look at 1-bit adding (no carry) in binary:

ABA + B (no carry)
110
101
011
000

If we substitute 1 with T and 0 with F, it’s clear that the table is the same as the XOR truth table. And if we only consider the carry for the 1-bit adding, we can find it’s just an AND operation.

Therefore, the half adder is easy to get, as shown below (A and B are inputs, R stands for the LSB of sum, C stands for the MSB of sum/carry):

halfadder

Full Adder

After getting the half adder, the next question is how to get the full adder based on it. Firstly, for the full adder, what we actually do is to calculate the A+B+Cin. The intuition tells us the LSB of A+B+Cin is just the no carry sum of the LSB of A+B and Cin, which is R = (A xor B) xor Cin. And for the carry, we can write down the results table and try to find the pattern.

A+BCinCout
1011
1001
0111
0100
0010
0000

We can see that the Cout is 1 if and only if either the carry of A+B is 1 or both the LSB of A+B and Cin are 1, which is Cout = (A and B) or (Cin and (A xor B)).

Therefore, the full adder is ready to get, as shown below:

onebitadder

8-Bit Full Adder

From a 1-bit full adder to an 8-bit adder is quite intuitive, just connect every bit of A and B to the corresponding bit adder, and the lower bit’s Cout connects to the higher one’s Cin.

(The bitadd in the picture below is the 1-bit full adder circuit shown above.)

8-Bit Adder/Subtractor

To implement subtraction, we need to know the idea of 2’s complement representation. Simply speaking, to make a number negative, just flip all the bits (0 to 1, 1 to 0) and add 1. In the circuit, what we should do are:

  1. Flip every bit of B when the sub-signal is 1.

  2. Add 1 when the sub-signal is 1.

Fortunately, we have a Cin in the LSB bit adder, which can be used for doing the additional add 1 process. But to do the flip, we do need to add some more components/gates. What we want for this gate is when the input of the sub-signal is 1, then flip the input of the B, and when the input of the sub-signal is 0, output the same as from B. We can find that this is just how the XOR gate works.

Therefore, we can get the 8-bit adder/subtractor, as shown below. (In my_adder.circ file, there is another circuit that doesn’t use the bitadd module, but that is too large to put into this report.)