public Memory(int iAddressSize, int iWordSize) { AddressSize = iAddressSize; WordSize = iWordSize; int registerNum = (int)Math.Pow(2.0, AddressSize); Input = new WireSet(WordSize); Output = new WireSet(WordSize); Address = new WireSet(AddressSize); Load = new Wire(); WireSet newLoad = new WireSet(1); newLoad[0].ConnectInput(Load); demux = new BitwiseMultiwayDemux(1, AddressSize); mux = new BitwiseMultiwayMux(WordSize, AddressSize); registers = new MultiBitRegister[registerNum]; WireSet AddressMirror = new WireSet(AddressSize); for (int j = 0; j < AddressSize; j++) { AddressMirror[j].ConnectInput(Address[AddressSize - 1 - j]); } demux.ConnectControl(AddressMirror); demux.ConnectInput(newLoad); for (int i = 0; i < registerNum; i++) { registers[i] = new MultiBitRegister(WordSize); registers[i].ConnectInput(Input); registers[i].Load.ConnectInput(demux.Outputs[i][0]); mux.ConnectInput(i, registers[i].Output); } mux.ConnectControl(Address); Output.ConnectInput(mux.Output); }
//your code here public Memory(int iAddressSize, int iWordSize) { AddressSize = iAddressSize; WordSize = iWordSize; Input = new WireSet(WordSize); Output = new WireSet(WordSize); Address = new WireSet(AddressSize); Load = new Wire(); //your code here demux = new BitwiseMultiwayDemux(1, iAddressSize); mux = new BitwiseMultiwayMux(iWordSize, iAddressSize); loadWs = new WireSet(1); loadWs[0].ConnectInput(Load); demux.ConnectControl(Address); demux.ConnectInput(loadWs); MultiBitRegister[] mbr = new MultiBitRegister[(int)Math.Pow(2, iAddressSize)]; for (int i = 0; i < mbr.Length; i++) { mbr[i] = new MultiBitRegister(iWordSize); mbr[i].ConnectInput(Input); mbr[i].Load.ConnectInput(demux.Outputs[i][0]); mux.Inputs[i].ConnectInput(mbr[i].Output); } mux.ConnectControl(Address); Output.ConnectInput(mux.Output); }
public BitwiseDemux(int iSize) { Size = iSize; Control = new Wire(); Input = new WireSet(Size); Output1 = new WireSet(Size); Output2 = new WireSet(Size); //your code here m_gDemux = new Demux[iSize]; WireSet ws_resault1 = new WireSet(iSize); WireSet ws_resault2 = new WireSet(iSize); //your code here for (int i = 0; i < iSize; i++) { m_gDemux[i] = new Demux(); m_gDemux[i].ConnectInput(Input[i]); m_gDemux[i].ConnectControl(Control); ws_resault1[i].ConnectInput(m_gDemux[i].Output1); ws_resault2[i].ConnectInput(m_gDemux[i].Output2); } Output1.ConnectInput(ws_resault1); Output2.ConnectInput(ws_resault2); }
// creating counter by using one multibit register and 1 full addr to increment by 1 // using mux to decide if to increment or to get new input public Counter(int iSize) { Size = iSize; Input = new WireSet(Size); Output = new WireSet(Size); Load = new Wire(); val = new WireSet(Size); val.SetValue(1); mux_op = new BitwiseMux(Size); adder = new MultiBitAdder(Size); register = new MultiBitRegister(Size); register.Load.Value = 1; mux_op.ConnectControl(Load); mux_op.ConnectInput1(adder.Output); mux_op.ConnectInput2(Input); register.ConnectInput(mux_op.Output); Output.ConnectInput(register.Output); adder.ConnectInput1(register.Output); adder.ConnectInput2(val); }
public BitwiseMultiwayMux(int iSize, int cControlBits) { Size = iSize; Output = new WireSet(Size); Control = new WireSet(cControlBits); Inputs = new WireSet[(int)Math.Pow(2, cControlBits)]; for (int i = 0; i < Inputs.Length; i++) { Inputs[i] = new WireSet(Size); } int numOfInputs = Inputs.Length; m_gBitwiseMux = new BitwiseMux[numOfInputs - 1]; for (int i = 0; i < m_gBitwiseMux.Length; i++) { m_gBitwiseMux[i] = new BitwiseMux(Size); } int currInputsToConnect = 0; int currGateToConnect = 0; int level = 1; int currNumOfGates = numOfInputs / 2; for (int j = 0; j < currNumOfGates; j++) //connecting all the inputs to gates { m_gBitwiseMux[currGateToConnect].ConnectInput1(Inputs[currInputsToConnect]); m_gBitwiseMux[currGateToConnect].ConnectInput2(Inputs[currInputsToConnect + 1]); m_gBitwiseMux[currGateToConnect].ConnectControl(Control[level - 1]); currGateToConnect++; currInputsToConnect += 2; } int previousGatesIndex = 0; for (level = 2; level <= numOfInputs; level++) // connectig gates' outputs to next level gates' inputs { currNumOfGates = currNumOfGates / 2; for (int j = 0; j < currNumOfGates; j++) { m_gBitwiseMux[currGateToConnect].ConnectInput1(m_gBitwiseMux[previousGatesIndex].Output); m_gBitwiseMux[currGateToConnect].ConnectInput2(m_gBitwiseMux[previousGatesIndex + 1].Output); m_gBitwiseMux[currGateToConnect].ConnectControl(Control[level - 1]); currGateToConnect++; previousGatesIndex += 2; } } Output.ConnectInput(m_gBitwiseMux[currGateToConnect - 1].Output); }
public BitwiseMultiwayMux(int iSize, int cControlBits) { Size = iSize; Output = new WireSet(Size); Control = new WireSet(cControlBits); Inputs = new WireSet[(int)Math.Pow(2, cControlBits)]; for (int i = 0; i < Inputs.Length; i++) { Inputs[i] = new WireSet(Size); } bwmx = new BitwiseMux[(int)Math.Pow(2, cControlBits) - 1]; for (int i = 0; i < bwmx.Length; i++) { bwmx[i] = new BitwiseMux(iSize); } //Level int j = 0; for (int i = 0; 2 * i + 2 < bwmx.Length; i++) { bwmx[i].ConnectInput1(bwmx[2 * i + 1].Output); bwmx[i].ConnectInput2(bwmx[2 * i + 2].Output); j = i + 1; } for (int i = 0; i < Inputs.Length; i = i + 2) { bwmx[j].ConnectInput1(Inputs[i]); bwmx[j].ConnectInput2(Inputs[i + 1]); j++; } int k = 0; for (int i = 0; i < bwmx.Length; i++) { if (i == (int)Math.Pow(2, k + 1) - 1) { k++; } bwmx[i].ConnectControl(Control[Control.Size - k - 1]); } Output.ConnectInput(bwmx[0].Output); }
// in order to find the right input, for each level of inputs making mux operation with the corresponding control bit // for all inputs in that level, after that repeat the procedure for the results of the muxes. // to accomplish that I made array of bitwise mux , in the size of Inputs -1 , because there always be 1 less mux than the inputs public BitwiseMultiwayMux(int iSize, int cControlBits) { //initilaize Size = iSize; ControlBits = cControlBits; Output = new WireSet(Size); Control = new WireSet(cControlBits); Inputs = new WireSet[(int)Math.Pow(2, cControlBits)]; bitwise_mux_operation = new BitwiseMux[Inputs.Length - 1]; for (int i = 0; i < Inputs.Length; i++) { Inputs[i] = new WireSet(Size); } for (int i = 0; i < bitwise_mux_operation.Length; i++) { bitwise_mux_operation[i] = new BitwiseMux(Size); } // make mux operation on the first level of inputs with the first control bit // so that the results will be stored in the first half of bitwise gates for (int i = 0; i < bitwise_mux_operation.Length / 2 + 1; i++) { bitwise_mux_operation[i].ConnectControl(Control[0]); bitwise_mux_operation[i].ConnectInput1(Inputs[i * 2]); bitwise_mux_operation[i].ConnectInput2(Inputs[(i * 2) + 1]); } // iterates for each control bit (starting from the second) and saves each pair of outputs in inputs of bitwise mux // so that the end result is in the last bitwisemux int start_of_input = 0, end_of_input = bitwise_mux_operation.Length / 2 + 1, counter = 0; for (int contol_bit = 1; contol_bit < cControlBits; contol_bit++) { for (int out_bit = start_of_input; out_bit < end_of_input; out_bit = out_bit + 2) { bitwise_mux_operation[counter + end_of_input].ConnectControl(Control[contol_bit]); bitwise_mux_operation[counter + end_of_input].ConnectInput1(bitwise_mux_operation[out_bit].Output); bitwise_mux_operation[counter + end_of_input].ConnectInput2(bitwise_mux_operation[out_bit + 1].Output); counter++; } counter = 0; start_of_input = end_of_input; end_of_input = (end_of_input + (bitwise_mux_operation.Length - end_of_input) / 2) + 1; } // connect the output Output.ConnectInput(bitwise_mux_operation[bitwise_mux_operation.Length - 1].Output); }
public BitwiseNotGate(int iSize) { Size = iSize; Input = new WireSet(Size); Output = new WireSet(Size); //your code here m_gNotGate = new NotGate[iSize]; WireSet ws_resault = new WireSet(iSize); for (int i = 0; i < iSize; i++) { m_gNotGate[i] = new NotGate(); m_gNotGate[i].ConnectInput(Input[i]); ws_resault[i].ConnectInput(m_gNotGate[i].Output); } Output.ConnectInput(ws_resault); }
//your code here public BitwiseMultiwayMux(int iSize, int cControlBits) { Size = iSize; Output = new WireSet(Size); Control = new WireSet(cControlBits); Inputs = new WireSet[(int)Math.Pow(2, cControlBits)]; WireSet[] wires = new WireSet[Inputs.Length]; BitwiseMux[] mux = new BitwiseMux[Inputs.Length - 1]; int muxIn = 0; for (int i = wires.Length - 1; i >= 0; i--) { Inputs[i] = new WireSet(Size); wires[i] = new WireSet(Size); wires[i] = Inputs[i]; } try { for (int currentControl = 0, wiresLength = wires.Length; wiresLength >= 2; wiresLength /= 2, currentControl++) { int outIN = 0; for (int i = 0; i < wiresLength; i += 2) { mux[muxIn] = new BitwiseMux(Size); if (currentControl <= cControlBits) { mux[muxIn].ConnectInput1(wires[i]); mux[muxIn].ConnectInput2(wires[i + 1]); mux[muxIn].ConnectControl(Control[currentControl]); wires[outIN] = mux[muxIn].Output; outIN++; muxIn++; } } } Output.ConnectInput(mux[muxIn - 1].Output); } catch (Exception e) { Console.WriteLine(e); } }
public BitwiseMultiwayMux(int iSize, int cControlBits) { Size = iSize; Output = new WireSet(Size); Control = new WireSet(cControlBits); Inputs = new WireSet[(int)Math.Pow(2, cControlBits)]; muxOutputs = new WireSet[Inputs.Length]; mux = new BitwiseMux[Inputs.Length]; int freeMux = 0; for (int i = 0; i < Inputs.Length; i++) { Inputs[i] = new WireSet(Size); muxOutputs[i] = new WireSet(Size); mux[i] = new BitwiseMux(Size); if (i % 2 == 1) { mux[freeMux].ConnectInput1(Inputs[i - 1]); mux[freeMux].ConnectInput2(Inputs[i]); mux[freeMux].ConnectControl(Control[0]); muxOutputs[freeMux].ConnectInput(mux[freeMux].Output); freeMux++; } } int muxNum = freeMux / 2, whereToStart = 0, whereToEnd = freeMux; for (int j = 1; j < cControlBits; j++) { for (int k = whereToStart; k < whereToEnd; k += 2) { mux[freeMux].ConnectInput1(muxOutputs[whereToStart]); mux[freeMux].ConnectInput2(muxOutputs[whereToStart + 1]); mux[freeMux].ConnectControl(Control[j]); muxOutputs[freeMux].ConnectInput(mux[freeMux].Output); freeMux++; whereToStart += 2; } whereToEnd = freeMux; } Output.ConnectInput(muxOutputs[freeMux - 1]); }
//your code here public BitwiseMultiwayMux(int iSize, int cControlBits) { Size = iSize; Output = new WireSet(Size); Control = new WireSet(cControlBits); Inputs = new WireSet[(int)Math.Pow(2, cControlBits)]; for (int i = 0; i < Inputs.Length; i++) { Inputs[i] = new WireSet(Size); } BitwiseMux[] mux = new BitwiseMux[(int)Math.Pow(2, cControlBits) - 1]; WireSet[] wires = new WireSet[(int)Math.Pow(2, cControlBits)]; int wiresLength = wires.Length; int currentMux = 0; int toSave = 0; int currentControl = 0; for (int i = 0; i < wires.Length; i++) { wires[i] = Inputs[i]; } while (wiresLength >= 2) { for (int i = 0; i < wiresLength; i = i + 2) { mux[currentMux] = new BitwiseMux(Size); mux[currentMux].ConnectInput1(wires[i]); mux[currentMux].ConnectInput2(wires[i + 1]); mux[currentMux].ConnectControl(Control[currentControl]); wires[toSave] = mux[currentMux].Output; toSave++; currentMux++; } wiresLength = wiresLength / 2; toSave = 0; currentControl++; } Output.ConnectInput(mux[currentMux - 1].Output); }
// creating memory component by using array of multi bit register // using 2 demux - one for the date input and one for the load input(to know if read/write) // using mux for the output public Memory(int iAddressSize, int iWordSize) { AddressSize = iAddressSize; WordSize = iWordSize; Input = new WireSet(WordSize); Output = new WireSet(WordSize); Address = new WireSet(AddressSize); Load = new Wire(); load_wireset = new WireSet(1); memory_cells = new MultiBitRegister[(int)Math.Pow(2, AddressSize)]; input_demux = new BitwiseMultiwayDemux(WordSize, AddressSize); input_demux_for_load = new BitwiseMultiwayDemux(1, AddressSize); output_mux = new BitwiseMultiwayMux(WordSize, AddressSize); for (int cell = 0; cell < memory_cells.Length; cell++) { memory_cells[cell] = new MultiBitRegister(WordSize); } load_wireset[0].ConnectInput(Load); input_demux.ConnectControl(Address); input_demux_for_load.ConnectControl(Address); output_mux.ConnectControl(Address); input_demux.ConnectInput(Input); input_demux_for_load.ConnectInput(load_wireset); for (int cell = 0; cell < memory_cells.Length; cell++) { memory_cells[cell].Load.ConnectInput(input_demux_for_load.Outputs[cell][0]); memory_cells[cell].ConnectInput(input_demux.Outputs[cell]); output_mux.Inputs[cell].ConnectInput(memory_cells[cell].Output); } Output.ConnectInput(output_mux.Output); }
public Memory(int iAddressSize, int iWordSize) { AddressSize = iAddressSize; WordSize = iWordSize; Input = new WireSet(WordSize); Output = new WireSet(WordSize); Address = new WireSet(AddressSize); Load = new Wire(); //your code here m_rMultiBit = new MultiBitRegister[(int)Math.Pow(2, AddressSize)]; m_gBWMultiMux = new BitwiseMultiwayMux(WordSize, AddressSize); //output m_gBWMultiMux.ConnectControl(Address); //connect all the inputs in loop m_gBWMultiDemux = new BitwiseMultiwayDemux(1, AddressSize); // Read/Write address m_gBWMultiDemux.ConnectControl(Address); WireSet connection = new WireSet(1); //because BWMultiwayDemux receives WireSet connection[0].ConnectInput(Load); m_gBWMultiDemux.ConnectInput(connection); //connect all the outputs in loop for (int i = 0; i < m_rMultiBit.Length; i++) { m_rMultiBit[i] = new MultiBitRegister(WordSize); //init m_rMultiBit[i].Load.ConnectInput(m_gBWMultiDemux.Outputs[i][0]); //connect Load from Demux output m_rMultiBit[i].ConnectInput(Input); // connect input m_gBWMultiMux.Inputs[i].ConnectInput(m_rMultiBit[i].Output); //connect output to Mux } Output.ConnectInput(m_gBWMultiMux.Output); }
public BitwiseMultiwayMux(int iSize, int cControlBits) { Size = iSize; Output = new WireSet(Size); Control = new WireSet(cControlBits); Inputs = new WireSet[(int)Math.Pow(2, cControlBits)]; for (int i = 0; i < Inputs.Length; i++) { Inputs[i] = new WireSet(Size); } WireSet[] temp; temp = new WireSet[Inputs.Length / 2]; int tempPointer = 0; int controlindex = 0; for (int i = 0; i + 1 < Inputs.Length; i += 2) { bitwiseMux = new BitwiseMux(iSize); bitwiseMux.ConnectControl(Control[controlindex]); bitwiseMux.ConnectInput1(Inputs[i]); bitwiseMux.ConnectInput2(Inputs[i + 1]); temp[tempPointer] = bitwiseMux.Output; tempPointer++; } controlindex++; int limit = temp.Length; while (limit != 0) { tempPointer = 0; for (int i = 0; i + 1 < limit; i += 2) { bitwiseMux = new BitwiseMux(iSize); bitwiseMux.ConnectControl(Control[controlindex]); bitwiseMux.ConnectInput1(temp[i]); bitwiseMux.ConnectInput2(temp[i + 1]); temp[tempPointer] = bitwiseMux.Output; tempPointer++; } controlindex++; limit /= 2; } Output.ConnectInput(temp[0]); /* Queue<WireSet> temp1 = new Queue<WireSet>(); * Queue<WireSet> temp2 = new Queue<WireSet>(); * * int controlindex = Control.Size-1; * * for (int i = 0; i < Inputs.Length ; i=i+2) * { * bitwiseMux = new BitwiseMux(iSize); * bitwiseMux.ConnectControl(Control[controlindex]); * bitwiseMux.ConnectInput1(Inputs[i]); * bitwiseMux.ConnectInput2(Inputs[i]); * temp1.Enqueue(bitwiseMux.Output); * * } * controlindex--; * * int level = controlindex; * while (level != -1) * { * * if (temp2.Count == 0) * { * while (temp1.Count >= 2) * { * bitwiseMux = new BitwiseMux(iSize); * bitwiseMux.ConnectControl(Control[controlindex]); * bitwiseMux.ConnectInput1(temp1.Dequeue()); * bitwiseMux.ConnectInput2(temp1.Dequeue()); * temp2.Enqueue(bitwiseMux.Output); * * } * } * else if (temp1.Count == 0) * { * while (temp2.Count >= 2) { * bitwiseMux = new BitwiseMux(iSize); * bitwiseMux.ConnectControl(Control[controlindex]); * bitwiseMux.ConnectInput1(temp2.Dequeue()); * bitwiseMux.ConnectInput2(temp2.Dequeue()); * temp1.Enqueue(bitwiseMux.Output); * } * } * controlindex--; * level--; * } * * if (temp1.Count != 0) * Output.ConnectInput( temp1.Dequeue()); * else * Output.ConnectInput( temp2.Dequeue()); * */ /* WireSet[] temp; * temp = new WireSet[Inputs.Length/2]; * * * for (int i =0;i+1<Inputs.Length ; i+=2) { * bitwiseMux = new BitwiseMux(iSize); * bitwiseMux.ConnectControl(Control[controlindex]); * bitwiseMux.ConnectInput1(Inputs[i]); * bitwiseMux.ConnectInput2(Inputs[i+1]); * * temp[tempPointer] = bitwiseMux.Output; * tempPointer++; * } * controlindex--; * * int limit = temp.Length; * * while (limit != -1) { * * tempPointer = 0; * for (int i = 0; i+1 < limit ;i+=2) { * bitwiseMux = new BitwiseMux(iSize); * bitwiseMux.ConnectControl(Control[controlindex]); * * bitwiseMux.ConnectInput1(temp[i]); * bitwiseMux.ConnectInput2(temp[i+1]); * temp[tempPointer] = bitwiseMux.Output; * tempPointer++; * } * * controlindex--; * if (limit == 0) break; * limit /= 2; * } * * Output = temp[0];*/ }
//your code here public ALU(int iSize) { Size = iSize; InputX = new WireSet(Size); InputY = new WireSet(Size); ZeroX = new Wire(); ZeroY = new Wire(); NotX = new Wire(); NotY = new Wire(); F = new Wire(); NotOutput = new Wire(); Negative = new Wire(); Zero = new Wire(); //Create and connect all the internal components Output = new WireSet(Size); BitwiseMux m_gZX = new BitwiseMux(Size); BitwiseMux m_gZY = new BitwiseMux(Size); WireSet zeroForXY = new WireSet(Size); zeroForXY.Set2sComplement(0); BitwiseNotGate m_gNotX = new BitwiseNotGate(Size); // reverse X BitwiseNotGate m_gNotY = new BitwiseNotGate(Size); // reverse Y BitwiseMux m_gNX = new BitwiseMux(Size); BitwiseMux m_gNY = new BitwiseMux(Size); BitwiseAndGate m_gBAnd = new BitwiseAndGate(Size); // X & Y MultiBitAdder mbAdder = new MultiBitAdder(Size); // X + Y BitwiseMux m_gF = new BitwiseMux(Size); BitwiseNotGate m_gNotFOut = new BitwiseNotGate(Size); // reverse F output BitwiseMux m_gN = new BitwiseMux(Size); MultiBitAndGate m_gZeroAnd = new MultiBitAndGate(Size); BitwiseNotGate m_gZeroNot = new BitwiseNotGate(Size); // connect inputX and input0 to ZX, connect ZXControl m_gZX.ConnectInput1(InputX); m_gZX.ConnectInput2(zeroForXY); m_gZX.ConnectControl(ZeroX); // connect bitwiseNotXIn to ZX output, connect ZXOut to NXIn1, connect bitwiseNotOut to NXIn2 m_gNotX.ConnectInput(m_gZX.Output); m_gNX.ConnectInput1(m_gZX.Output); m_gNX.ConnectInput2(m_gNotX.Output); m_gNX.ConnectControl(NotX); // connect inputY and input0 to ZY, connect ZYControl m_gZY.ConnectInput1(InputY); m_gZY.ConnectInput2(zeroForXY); m_gZY.ConnectControl(ZeroY); // connect bitwiseNotYIn to ZY output, connect ZYOut to NYIn1, connect bitwiseNotYOut to NYIn2 m_gNotY.ConnectInput(m_gZY.Output); m_gNY.ConnectInput1(m_gZY.Output); m_gNY.ConnectInput2(m_gNotY.Output); m_gNY.ConnectControl(NotY); // connect NXOut to bitwiseAndIn1, connect NYOut to bitwiseAndIn2 m_gBAnd.ConnectInput1(m_gNX.Output); m_gBAnd.ConnectInput2(m_gNY.Output); // connect NXOut to mbAdderIn1, connect NYOut to mbAdderIn2 mbAdder.ConnectInput1(m_gNX.Output); mbAdder.ConnectInput2(m_gNY.Output); // connect bitwiseAndOut to F_In1, connect mbAdderOut to F_In2 m_gF.ConnectInput1(m_gBAnd.Output); m_gF.ConnectInput2(mbAdder.Output); m_gF.ConnectControl(F); //connect F_Out to bitwiseNotFIn m_gNotFOut.ConnectInput(m_gF.Output); // connect F_Out to N_In1, connect bitwiseNotFOut to N_In2 m_gN.ConnectInput1(m_gF.Output); m_gN.ConnectInput2(m_gNotFOut.Output); m_gN.ConnectControl(NotOutput); // connect N_Out to Output Output.ConnectInput(m_gN.Output); // connect negativeIndicator to last Output wire Negative.ConnectInput(Output[Size - 1]); // connect ZeroIndicator depending on zeroNot and zeroAnd concatenation m_gZeroNot.ConnectInput(Output); m_gZeroAnd.ConnectInput(m_gZeroNot.Output); Zero.ConnectInput(m_gZeroAnd.Output); }
public void ConnectInput(WireSet ws) { m_wsInput.ConnectInput(ws); }
public ALU(int iSize) { Size = iSize; InputX = new WireSet(Size); InputY = new WireSet(Size); ZeroX = new Wire(); ZeroY = new Wire(); NotX = new Wire(); NotY = new Wire(); F = new Wire(); NotOutput = new Wire(); Negative = new Wire(); Zero = new Wire(); //Create and connect all the internal components Output = new WireSet(Size); m_wsZero = new WireSet(Size); for (int i = 0; i < Size; i++) { m_wsZero[i].Value = 0; } m_gZxMux = new BitwiseMultiwayMux(Size, 1); m_gZxMux.ConnectInput(0, InputX); m_gZxMux.ConnectInput(1, m_wsZero); m_gZxMux.Control[0].ConnectInput(ZeroX); m_gNxNot = new BitwiseNotGate(Size); m_gNxNot.ConnectInput(m_gZxMux.Output); m_gNxMux = new BitwiseMultiwayMux(Size, 1); m_gNxMux.ConnectInput(0, m_gZxMux.Output); m_gNxMux.ConnectInput(1, m_gNxNot.Output); m_gNxMux.Control[0].ConnectInput(NotX); m_gZyMux = new BitwiseMultiwayMux(Size, 1); m_gZyMux.ConnectInput(0, InputY); m_gZyMux.ConnectInput(1, m_wsZero); m_gZyMux.Control[0].ConnectInput(ZeroY); m_gNyNot = new BitwiseNotGate(Size); m_gNyNot.ConnectInput(m_gZyMux.Output); m_gNyMux = new BitwiseMultiwayMux(Size, 1); m_gNyMux.ConnectInput(0, m_gZyMux.Output); m_gNyMux.ConnectInput(1, m_gNyNot.Output); m_gNyMux.Control[0].ConnectInput(NotY); m_gFAdder = new MultiBitAdder(Size); m_gFAdder.ConnectInput1(m_gNxMux.Output); m_gFAdder.ConnectInput2(m_gNyMux.Output); m_gFAnd = new BitwiseAndGate(Size); m_gFAnd.ConnectInput1(m_gNxMux.Output); m_gFAnd.ConnectInput2(m_gNyMux.Output); m_gFMux = new BitwiseMultiwayMux(Size, 1); m_gFMux.ConnectInput(0, m_gFAnd.Output); m_gFMux.ConnectInput(1, m_gFAdder.Output); m_gFMux.Control[0].ConnectInput(F); m_gNoNot = new BitwiseNotGate(Size); m_gNoNot.ConnectInput(m_gFMux.Output); m_gNoMux = new BitwiseMultiwayMux(Size, 1); m_gNoMux.ConnectInput(0, m_gFMux.Output); m_gNoMux.ConnectInput(1, m_gNoNot.Output); m_gNoMux.Control[0].ConnectInput(NotOutput); Output.ConnectInput(m_gNoMux.Output); m_gZrOr = new MultiBitOrGate(Size); m_gZrOr.ConnectInput(Output); m_gZrNot = new NotGate(); m_gZrNot.ConnectInput(m_gZrOr.Output); Zero.ConnectInput(m_gZrNot.Output); Negative.ConnectInput(Output[Size - 1]); }
public void ConnectInput(WireSet wInput) { Input.ConnectInput(wInput); }
public ALU(int iSize) { Size = iSize; InputX = new WireSet(Size); InputY = new WireSet(Size); ZeroX = new Wire(); ZeroY = new Wire(); NotX = new Wire(); NotY = new Wire(); F = new Wire(); NotOutput = new Wire(); Negative = new Wire(); Zero = new Wire(); Output = new WireSet(iSize); muxZx = new BitwiseMux(iSize); muxZy = new BitwiseMux(iSize); muxNx = new BitwiseMux(iSize); muxNy = new BitwiseMux(iSize); muxF = new BitwiseMux(iSize); muxNo = new BitwiseMux(iSize); notNx = new BitwiseNotGate(iSize); notNy = new BitwiseNotGate(iSize); notNo = new BitwiseNotGate(iSize); andF = new BitwiseAndGate(iSize); adderF = new MultiBitAdder(iSize); wireX0 = new WireSet(iSize); wireX0.Set2sComplement(0); wireY0 = new WireSet(iSize); wireY0.Set2sComplement(0); isZeroNot = new BitwiseNotGate(iSize); isZeroMultiAnd = new MultiBitAndGate(iSize); muxZx.ConnectInput1(InputX); muxZx.ConnectInput2(wireX0); muxZx.ConnectControl(ZeroX); muxNx.ConnectInput1(muxZx.Output); notNx.ConnectInput(muxZx.Output); muxNx.ConnectInput2(notNx.Output); muxNx.ConnectControl(NotX); andF.ConnectInput1(muxNx.Output); adderF.ConnectInput1(muxNx.Output); muxZy.ConnectInput1(InputY); muxZy.ConnectInput2(wireY0); muxZy.ConnectControl(ZeroY); muxNy.ConnectInput1(muxZy.Output); notNy.ConnectInput(muxZy.Output); muxNy.ConnectInput2(notNy.Output); muxNy.ConnectControl(NotY); andF.ConnectInput2(muxNy.Output); adderF.ConnectInput2(muxNy.Output); //now from muxF muxF.ConnectInput1(andF.Output); muxF.ConnectInput2(adderF.Output); muxF.ConnectControl(F); muxNo.ConnectInput1(muxF.Output); notNo.ConnectInput(muxF.Output); muxNo.ConnectInput2(notNo.Output); muxNo.ConnectControl(NotOutput); Output.ConnectInput(muxNo.Output); Negative.ConnectInput(muxNo.Output[iSize - 1]); isZeroNot.ConnectInput(muxNo.Output); isZeroMultiAnd.ConnectInput(isZeroNot.Output); Zero.ConnectInput(isZeroMultiAnd.Output); }