How to Build an Arithmetic Logic Unit in Logisim-evolution: 8-Bit ALU Tutorial
Direct Answer: Designing an 8-Bit Arithmetic Logic Unit in Logisim-evolution
An Arithmetic Logic Unit (ALU) is the computational core of a central processor, executing arithmetic operations (addition, subtraction) and bitwise boolean logic (AND, OR, XOR, NOT, SLT) on two $N$-bit operands. In Logisim-evolution, an 8-bit modular ALU consists of two 8-bit input buses (A[7:0], B[7:0]), a 3-bit operation code selector (ALU_Sel[2:0]), an 8-to-1 8-bit multiplexer to select the computational result, and four canonical status flags: Negative (N) derived from the MSB, Zero (Z) generated by an 8-input NOR gate across all output bits, Carry (C) captured from the adder carry-out, and Overflow (V) computed via $C6 \oplus C7$ for signed two’s complement boundary verification.
Recommended Computer Architecture Textbooks and Physical Hardware
The ALU is the centerpiece of university digital logic and computer architecture courses. The following authoritative textbooks and physical FPGA development boards provide essential theoretical foundation and physical verification:
Digital Design & Computer Architecture
By David Harris and Sarah Harris. Covers complete ALU schematic construction, carry-lookahead adders (CLA), status flag equations, and HDL mapping for real processors.
Digilent Basys 3 Artix-7 FPGA
Synthesize your 8-bit Logisim ALU on physical silicon. Use 16 slide switches for operands A and B, pushbuttons for opcode selection, and onboard LEDs for output result and status flags.
Comprehensive 8-Operation ALU Control Truth Table
A standard educational 8-bit ALU implements four arithmetic operations and four bitwise logic operations selected by a 3-bit control code (ALU_Sel[2:0]):
| Opcode (ALU_Sel) | Operation Mnemonic | Mathematical Expression | Sub Bit | Active Status Flags |
|---|---|---|---|---|
| 000 | ADD | Y = A + B | 0 | Negative (N), Zero (Z), Carry (C), Overflow (V) |
| 001 | SUB | Y = A − B = A + (~B) + 1 | 1 | Negative (N), Zero (Z), Borrow (C), Overflow (V) |
| 010 | AND | Y = A & B | 0 | Negative (N), Zero (Z) |
| 011 | OR | Y = A | B | 0 | Negative (N), Zero (Z) |
| 100 | XOR | Y = A ⊕ B | 0 | Negative (N), Zero (Z) |
| 101 | NOT (Invert A) | Y = ~A | 0 | Negative (N), Zero (Z) |
| 110 | SLL (Shift Left) | Y = A << 1 (Zero injected into LSB) | 0 | Negative (N), Zero (Z), Carry (A[7]) |
| 111 | SLT (Set Less Than) | Y = (A < B signed) ? 0x01 : 0x00 | 1 | Zero (Z) |
Hierarchical Construction Stages in Logisim Schematics
Build your ALU cleanly by decomposing the design into four modular subcircuits:
Phase 1: Arithmetic Adder and Subtractor Subcircuit
The arithmetic core performs both addition and subtraction using a unified adder:
- Place an 8-bit Adder from the Arithmetic library.
- Invert operand
Bconditionally using an 8-bit XOR gate receiving busB[7:0]and a single control bitSubbroadcast across all 8 inputs. - Connect
Subdirectly to theCin(Carry-In) port of the adder. For addition (Sub = 0), $Y = A + B + 0$. For subtraction (Sub = 1), $Y = A + (\sim B) + 1 = A – B$. - Output the 8-bit sum, the Carry-Out bit (
Cout), and the carry into the MSB (C_in_msb) for overflow logic.
Phase 2: Bitwise Logic and Shifter Array
Construct parallel combinational logic paths accepting 8-bit buses A and B:
- AND Gate: 8-bit wide AND gate producing
A & B. - OR Gate: 8-bit wide OR gate producing
A | B. - XOR Gate: 8-bit wide XOR gate producing
A ⊕ B. - NOT Gate: 8-bit wide inverter producing
~A. - Shift Left Logical (SLL): Use a Splitter on bus
Ato route bitsA[6:0]into output linesY[7:1], while wiring a constant0to output bitY[0]. The ejected bitA[7]routes to the shift carry flag.
Phase 3: Multiplexer Result Routing
Place an 8-to-1 Multiplexer (Data Bits: 8, Select Bits: 3) from the Plexers library:
Wire input 0 to ADD, input 1 to SUB, input 2 to AND, input 3 to OR, input 4 to XOR, input 5 to NOT, input 6 to SLL, and input 7 to SLT. The 3-bit input pin ALU_Sel connects to the multiplexer select port, cleanly switching the primary output bus Y[7:0].
Phase 4: Status Flag Generation Logic (NZCV)
The four status flags inform downstream processor branch decision logic:
- Negative Flag (N): Tap the most significant bit (MSB,
Y[7]) using a splitter. In two’s complement notation, a leading 1 signifies a negative quantity. - Zero Flag (Z): Route all 8 output bits
Y[7:0]into an 8-input NOR gate. The output is1if and only if all result bits are0. - Carry Flag (C): Driven directly by the adder’s Carry-Out during ADD operations, and inverted for Borrow during SUB.
- Overflow Flag (V): Compute signed two’s complement overflow: $V = C_{in\_msb} \oplus C_{out\_msb} = C6 \oplus C7$. This activates when adding two positives produces a negative or adding two negatives produces a positive.
Frequent Traps When Building ALUs in Logisim
Avoid these common logic mistakes when constructing your ALU subcircuit:
Trap 1: Set on Less Than (SLT) Sign Confusion
Problem: Simply checking if A − B < 0 via the result sign bit Y[7] fails when arithmetic overflow occurs (e.g. comparing +120 and −120).
The Fix: Compute SLT using the combined formula: SLT = Sign_Bit ⊕ Overflow_Flag (N ⊕ V). This yields mathematically flawless signed comparison across all integer boundaries.
Trap 2: Floating Bus Mismatches on Plexers
Problem: Feeding a 1-bit SLT result directly into an 8-bit multiplexer input throws a yellow/orange bit-width error in Logisim.
The Fix: Pass the 1-bit SLT flag through a Bit Extender (set to zero extension) to expand it into an 8-bit bus (0x00 or 0x01) before the multiplexer.
Trap 3: Carry Flag Gating on Logic Operations
Problem: Leaving the Carry flag wired continuously to the adder output causes false carry assertions during AND or OR operations.
The Fix: Gate the Carry and Overflow outputs using an AND gate enabled only when ALU_Sel[2:1] == 00 (arithmetic mode).
Trap 4: Subtraction Borrow vs Carry Polarity
Problem: In x86 architecture, Borrow is active-low (C = 0 indicates borrow). In ARM/MIPS, Carry is active-high.
The Fix: Follow your target architecture convention: in standard MIPS, Carry = Cout directly from the two’s complement adder.
Curriculum Progression from ALU to Microprocessors
Once your ALU passes all operation tests, integrate it into higher-level processor architectures:
Frequently Asked Questions About Building Logisim ALUs
How does an ALU calculate two’s complement overflow?
Overflow occurs when arithmetic exceeds the range of signed integers. In binary adders, it is computed by XORing the carry entering the most significant bit (MSB) with the carry leaving the MSB: V = C_{in\_msb} ⊕ C_{out\_msb}. If the two carries differ, an overflow has occurred.
Can Logisim-evolution synthesize a 32-bit or 64-bit ALU?
Yes. Logisim-evolution’s built-in arithmetic components and multiplexers support bit-widths up to 32 bits natively. For 64-bit architectures, you can either cascade two 32-bit units with carry propagation or configure custom bus bit-widths.
What is the difference between Ripple-Carry and Carry-Lookahead Adders in an ALU?
A Ripple-Carry Adder chains carry signals through each 1-bit full adder sequentially, resulting in $O(N)$ propagation latency. A Carry-Lookahead Adder (CLA) computes carry signals simultaneously using Generate ($G_i = A_i \cdot B_i$) and Propagate ($P_i = A_i \oplus B_i$) logic, reducing latency to $O(\log N)$ at the cost of additional logic gates.
How do I implement Set on Less Than (SLT) for signed numbers?
Subtract operand B from operand A ($A – B$) and evaluate the expression N ⊕ V (Negative flag XOR Overflow flag). If $N \oplus V = 1$, then $A < B$. Output a 32-bit word containing 0x00000001; otherwise output 0x00000000.
