Skip to content

Spec: Multiplexers, Decoders, and ALU Components ​

Overview ​

Add a library of higher-level combinational logic components including multiplexers, demultiplexers, encoders, decoders, comparators, adders, and an ALU. These are standard building blocks that save users from constructing them from individual gates.

Motivation ​

Students and designers frequently need these components. Building an 8-to-1 MUX from gates requires ~30 gates and extensive wiring. Providing pre-built, parameterized versions dramatically speeds up circuit design and allows focus on system-level architecture rather than gate-level plumbing.

Requirements ​

Functional Requirements ​

Multiplexers ​

  1. 2-to-1 MUX: 2 data inputs, 1 select, 1 output.
  2. 4-to-1 MUX: 4 data inputs, 2 select lines, 1 output.
  3. 8-to-1 MUX: 8 data inputs, 3 select lines, 1 output.
  4. 16-to-1 MUX: 16 data inputs, 4 select lines, 1 output.

Demultiplexers ​

  1. 1-to-2 DEMUX: 1 data input, 1 select, 2 outputs.
  2. 1-to-4 DEMUX: 1 data input, 2 select lines, 4 outputs.
  3. 1-to-8 DEMUX: 1 data input, 3 select lines, 8 outputs.

Encoders/Decoders ​

  1. 2-to-4 Decoder: 2 inputs, 4 outputs (one-hot), optional enable.
  2. 3-to-8 Decoder: 3 inputs, 8 outputs (one-hot), optional enable.
  3. 8-to-3 Priority Encoder: 8 inputs, 3-bit binary output + valid flag.
  4. BCD to 7-Segment Decoder: 4-bit BCD input, 7 segment outputs.

Arithmetic ​

  1. Half Adder: 2 inputs (A, B), 2 outputs (Sum, Carry).
  2. Full Adder: 3 inputs (A, B, Cin), 2 outputs (Sum, Cout).
  3. N-bit Ripple Carry Adder: Configurable width (4/8/16 bit).
  4. N-bit Comparator: A > B, A = B, A < B outputs.
  5. N-bit ALU: Configurable operations (ADD, SUB, AND, OR, XOR, NOT, SHL, SHR) selected by opcode input.

Non-Functional Requirements ​

  • All components must have configurable propagation delay.
  • Shape definitions must clearly show pin labels and function.
  • Components should be visually compact but readable.
  • Each component type should include a datasheet-style tooltip/description.

Design ​

Component Hierarchy ​

Components/Combinational/
├── Multiplexers/
│   ├── Mux2To1.cs
│   ├── Mux4To1.cs
│   ├── Mux8To1.cs
│   └── Mux16To1.cs
├── Demultiplexers/
│   ├── Demux1To2.cs
│   ├── Demux1To4.cs
│   └── Demux1To8.cs
├── Encoders/
│   ├── Decoder2To4.cs
│   ├── Decoder3To8.cs
│   ├── PriorityEncoder8To3.cs
│   └── BcdTo7Segment.cs
└── Arithmetic/
    ├── HalfAdder.cs
    ├── FullAdder.cs
    ├── RippleCarryAdder.cs
    ├── Comparator.cs
    └── ArithmeticLogicUnit.cs

Evaluation Logic (Example: 4-to-1 MUX) ​

csharp
public override void Evaluate()
{
    int select = (S1.SignalValue << 1) | S0.SignalValue;
    Output.SignalState = select switch
    {
        0 => D0.SignalState,
        1 => D1.SignalState,
        2 => D2.SignalState,
        3 => D3.SignalState,
        _ => Signal.Floating
    };
}

Toolbox Organization ​

New category in toolbox: "Combinational" with sub-groups:

  • Multiplexers
  • Decoders/Encoders
  • Arithmetic

Shape Definitions ​

Each component gets a JSON shape file with:

  • Rectangular body with function label (e.g., "MUX", "DEC", "ALU").
  • Clearly labeled input/output pins.
  • Select/control pins on a distinct side (typically bottom or left).

Implementation Tasks ​

  1. Create Components/Combinational/ directory structure in Core.
  2. Implement MUX components (2/4/8/16-to-1).
  3. Implement DEMUX components (1-to-2/4/8).
  4. Implement Decoder components (2-to-4, 3-to-8, BCD-to-7seg).
  5. Implement Priority Encoder.
  6. Implement arithmetic components (Half/Full Adder, Ripple Carry, Comparator).
  7. Implement ALU with opcode-selectable operations.
  8. Create JSON shape definitions for all new components.
  9. Add components to toolbox under "Combinational" category.
  10. Write documentation pages for each component type.

Risks & Open Questions ​

  • Should N-bit components use bus pins (depends on Bus/Bundle Wires spec)?
  • How to handle enable/active-low variants (separate components or configurable property)?
  • Should the ALU opcode set be fixed or user-configurable?
  • Consider adding carry-lookahead adder as an advanced option?

Priority ​

High — Low implementation effort, high everyday utility for users.