1 package era.mi.logic.components;
3 import era.mi.logic.Bit;
4 import era.mi.logic.WireArray;
7 * Models a Multiplexer. A is selected when select bit is 1, B when select bit is 0. Outputs X otherwise.
11 public class Mux extends BasicComponent
13 private WireArray a, b, out;
14 private WireArray select;
15 private final int size;
18 * {@link WireArray}s a, b and out must be of uniform length, select
19 * @param a Must be of uniform length with b and out.
20 * @param b Must be of uniform length with a and out.
22 * @param out Must be of uniform length with a and b.
24 public Mux(int processTime, WireArray a, WireArray b, WireArray select, WireArray out)
28 if(b.length() != out.length() || b.length() != size)
29 throw new IllegalArgumentException("All MUX wire arrays must be of uniform length!");
35 select.addObserver(this);
40 protected void compute()
43 switch(select.getValue())
48 out.feedSignals(active.getValues());
51 Bit[] newValues = new Bit[size];
52 for(int i = 0; i < size; i++)
54 out.feedSignals(newValues);
58 public WireArray getA()
63 public WireArray getB()
68 public WireArray getOut()
73 public WireArray getSelect()