What you will build
A 1-bit ALU slice, then a 4-bit ALU made of four slices with a zero flag Z and an overflow flag V. Plan on about three hours. You need the adder project first: the slice uses a full adder as a subcircuit.
The 1-bit ALU slice
Inputs, outputs and operations
Pins: A, B, Cin, Binv and a 2-bit Op, and outputs R and Cout. Inside, B2 is B XOR Binv. The four results are AND (A·B2), OR (A + B2), SUM (a full adder of A, B2 and Cin) and XOR (A ⊕ B2). A 4-input multiplexer with Select Bits 2 picks R by Op.
| Op | Operation |
|---|---|
| 00 | AND |
| 01 | OR |
| 10 | SUM |
| 11 | XOR |
Cout is the full adder’s carry for every Op. The 4-bit ALU only uses it when Op is 10.
Describe this circuit
Components: Input pin A; Input pin B; Input pin Binv; Input pin Cin; Input pin Op; XOR Gate B2; AND Gate 1; OR Gate 1; XOR Gate 2; fa sum; Multiplexer 1; Output pin R; Output pin Cout.
- Input pin A connects to AND Gate 1, OR Gate 1, XOR Gate 2, fa sum (net A, a).
- Input pin B connects to XOR Gate B2 (net B, b).
- Input pin Binv connects to XOR Gate B2 (net Binv, bi).
- Input pin Cin connects to fa sum (net Cin, ci).
- Input pin Op connects to Multiplexer 1 (net Op, op), 2 bits wide.
- XOR Gate B2 connects to AND Gate 1, OR Gate 1, XOR Gate 2, fa sum (net b2).
- AND Gate 1 connects to Multiplexer 1 (net r00).
- OR Gate 1 connects to Multiplexer 1 (net r01).
- XOR Gate 2 connects to Multiplexer 1 (net r11).
- fa sum connects to Multiplexer 1 (net r10).
- fa sum connects to Output pin Cout (net co, Cout).
- Multiplexer 1 connects to Output pin R (net R).
| # | A | B | Binv | Cin | Op | R | Cout |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0x2 | 0 | 0 | |
| 0 | 0 | 0 | 1 | 0x2 | 1 | 0 | |
| 0 | 0 | 1 | 0 | 0x2 | 1 | 0 | |
| 0 | 0 | 1 | 1 | 0x2 | 0 | 1 | |
| 0 | 1 | 0 | 0 | 0x2 | 1 | 0 | |
| 0 | 1 | 0 | 1 | 0x2 | 0 | 1 | |
| 0 | 1 | 1 | 0 | 0x2 | 0 | 0 | |
| 0 | 1 | 1 | 1 | 0x2 | 1 | 0 | |
| 1 | 0 | 0 | 0 | 0x2 | 1 | 0 | |
| 1 | 0 | 0 | 1 | 0x2 | 0 | 1 | |
| 1 | 0 | 1 | 0 | 0x2 | 0 | 1 | |
| 1 | 0 | 1 | 1 | 0x2 | 1 | 1 | |
| 1 | 1 | 0 | 0 | 0x2 | 0 | 1 | |
| 1 | 1 | 0 | 1 | 0x2 | 1 | 1 | |
| 1 | 1 | 1 | 0 | 0x2 | 1 | 0 | |
| 1 | 1 | 1 | 1 | 0x2 | 0 | 1 |
Download the 1-bit ALU or its 2.7.1 version. The multiplexer’s data inputs are numbered from the top in its default orientation (multiplexers).
4-bit ALU from four slices
Chaining the slices
Four cells in a carry chain, sharing Binv and Op. Binv also drives the carry in of cell 0, so Op = 10 with Binv = 1 subtracts: A + NOT B + 1. Pins: A[4], B[4], Binv and Op[2] in; R[4], Cout, Z and V out.
Describe this circuit
Components: Input pin A; Splitter 1; Input pin B; Splitter 2; Input pin Binv; Input pin Op; alu1 cell0; alu1 cell1; alu1 cell2; alu1 cell3; Splitter 3; Output pin R; Output pin Cout; NOR Gate 1; Output pin Z; XOR Gate 1; Output pin V.
- Input pin A connects to Splitter 1 (net A), 4 bits wide.
- Splitter 1 connects to alu1 cell0 (net A0).
- Splitter 1 connects to alu1 cell1 (net A1).
- Splitter 1 connects to alu1 cell2 (net A2).
- Splitter 1 connects to alu1 cell3 (net A3).
- Input pin B connects to Splitter 2 (net B), 4 bits wide.
- Splitter 2 connects to alu1 cell0 (net B0).
- Splitter 2 connects to alu1 cell1 (net B1).
- Splitter 2 connects to alu1 cell2 (net B2).
- Splitter 2 connects to alu1 cell3 (net B3).
- Input pin Binv connects to alu1 cell0, alu1 cell1, alu1 cell2, alu1 cell3 (net Binv, bi, c0).
- Input pin Op connects to alu1 cell0, alu1 cell1, alu1 cell2, alu1 cell3 (net Op, op), 2 bits wide.
- alu1 cell0 connects to Splitter 3, NOR Gate 1 (net r0).
- alu1 cell0 connects to alu1 cell1 (net c1).
- alu1 cell1 connects to Splitter 3, NOR Gate 1 (net r1).
- alu1 cell1 connects to alu1 cell2 (net c2).
- alu1 cell2 connects to Splitter 3, NOR Gate 1 (net r2).
- alu1 cell2 connects to alu1 cell3, XOR Gate 1 (net c3).
- alu1 cell3 connects to Splitter 3, NOR Gate 1 (net r3).
- alu1 cell3 connects to Output pin Cout, XOR Gate 1 (net c4, Cout).
- Splitter 3 connects to Output pin R (net R), 4 bits wide.
- NOR Gate 1 connects to Output pin Z (net Z).
- XOR Gate 1 connects to Output pin V (net V).
Control table
| Binv / Op | Operation |
|---|---|
| 0 / 00 | AND |
| 0 / 01 | OR |
| 0 / 10 | ADD |
| 1 / 10 | SUB |
| 0 / 11 | XOR |
The other Binv combinations (for example 1 / 00) give AND, OR and XOR with NOT B. They are side effects, not operations we support.
Zero and overflow flags
Z is a NOR of the four result bits. V is the carry into bit 3 XOR the carry out of bit 3, and only means something when Op is 10, so our vector marks V as don’t care (x) on other rows. The vector uses the special value that Logisim accepts for don’t care in a test vector.
| # | A | B | Binv | Op | R | Cout | Z | V |
|---|---|---|---|---|---|---|---|---|
| 0x0 | 0x0 | 0 | 0x2 | 0x0 | 0 | 1 | 0 | |
| 0x0 | 0x0 | 1 | 0x2 | 0x0 | 1 | 1 | 0 | |
| 0x0 | 0x1 | 0 | 0x2 | 0x1 | 0 | 0 | 0 | |
| 0x0 | 0x1 | 1 | 0x2 | 0xf | 0 | 0 | 0 | |
| 0x0 | 0x2 | 0 | 0x2 | 0x2 | 0 | 0 | 0 | |
| 0x0 | 0x2 | 1 | 0x2 | 0xe | 0 | 0 | 0 | |
| 0x0 | 0x3 | 0 | 0x2 | 0x3 | 0 | 0 | 0 | |
| 0x0 | 0x3 | 1 | 0x2 | 0xd | 0 | 0 | 0 | |
| 0x0 | 0x4 | 0 | 0x2 | 0x4 | 0 | 0 | 0 | |
| 0x0 | 0x4 | 1 | 0x2 | 0xc | 0 | 0 | 0 | |
| 0x0 | 0x5 | 0 | 0x2 | 0x5 | 0 | 0 | 0 | |
| 0x0 | 0x5 | 1 | 0x2 | 0xb | 0 | 0 | 0 | |
| 0x0 | 0x6 | 0 | 0x2 | 0x6 | 0 | 0 | 0 | |
| 0x0 | 0x6 | 1 | 0x2 | 0xa | 0 | 0 | 0 | |
| 0x0 | 0x7 | 0 | 0x2 | 0x7 | 0 | 0 | 0 | |
| 0x0 | 0x7 | 1 | 0x2 | 0x9 | 0 | 0 | 0 |
Download the 4-bit ALU, its 2.7.1 version and the vector.
What is not in this version
We did not build the whole-word 8-bit and 16-bit ALUs with a carry and negative flag, or a calculator. The 4-bit design above is the one we tested.
Check yourself
Back to adders, or see what is inside these files in the .circ file page.