public SingleBitRegister() { Input = new Wire(); Load = new Wire(); Output = new Wire(); mux = new MuxGate(); ff = new DFlipFlopGate(); mux.ConnectControl(Load); mux.ConnectInput1(ff.Output); mux.ConnectInput2(Input); ff.ConnectInput(mux.Output); Output.ConnectInput(ff.Output); }
public HalfAdder() { CarryOutput = new Wire(); m_xorGate = new XorGate(); m_andGate = new AndGate(); m_xorGate.Input1.ConnectInput(Input1); m_xorGate.Input2.ConnectInput(Input2); Output.ConnectInput(m_xorGate.Output); m_andGate.Input1.ConnectInput(Input1); m_andGate.Input2.ConnectInput(Input2); CarryOutput.ConnectInput(m_andGate.Output); }
public HalfAdder() { CarryOutput = new Wire(); xor = new XorGate(); and = new AndGate(); xor.ConnectInput1(Input1); xor.ConnectInput2(Input2); and.ConnectInput1(Input1); and.ConnectInput2(Input2); CarryOutput.ConnectInput(and.Output); Output.ConnectInput(xor.Output); }
public HalfAdder() { //your code here m_gXor = new XorGate(); m_gAnd = new AndGate(); m_gXor.ConnectInput1(Input1); m_gXor.ConnectInput2(Input2); Output.ConnectInput(m_gXor.Output); m_gAnd.ConnectInput1(Input1); m_gAnd.ConnectInput2(Input2); CarryOutput = new Wire(); CarryOutput.ConnectInput(m_gAnd.Output); }
// creating the halfadder by using the "xor" and "and gates" for the output and the carry public HalfAdder() { // initilaize the gates CarryOutput = new Wire(); xor_op = new XorGate(); and_op = new AndGate(); //xor operation for the sum output xor_op.ConnectInput1(Input1); xor_op.ConnectInput2(Input2); //and operation for the carry output and_op.ConnectInput1(Input1); and_op.ConnectInput2(Input2); //connecting outputs Output.ConnectInput(xor_op.Output); CarryOutput.ConnectInput(and_op.Output); }
public FullAdder() { CarryInput = new Wire(); //your code here CarryOutput = new Wire(); m_halfAdder1 = new HalfAdder(); m_halfAdder2 = new HalfAdder(); m_xorGate = new XorGate(); m_halfAdder1.ConnectInput1(Input1); m_halfAdder1.ConnectInput2(Input2); m_halfAdder2.ConnectInput1(m_halfAdder1.Output); m_halfAdder2.ConnectInput2(CarryInput); m_xorGate.ConnectInput1(m_halfAdder1.CarryOutput); m_xorGate.ConnectInput2(m_halfAdder2.CarryOutput); Output.ConnectInput(m_halfAdder2.Output); CarryOutput.ConnectInput(m_xorGate.Output); }
public FullAdder() { CarryInput = new Wire(); //your code here CarryOutput = new Wire(); m_gHf = new HalfAdder(); m_gHf.ConnectInput1(Input1); m_gHf.ConnectInput2(Input2); m_gHfCin = new HalfAdder(); m_gHfCin.ConnectInput1(m_gHf.Output); m_gHfCin.ConnectInput2(CarryInput); Output.ConnectInput(m_gHfCin.Output); m_gOrCout = new OrGate(); m_gOrCout.ConnectInput1(m_gHf.CarryOutput); m_gOrCout.ConnectInput2(m_gHfCin.CarryOutput); CarryOutput.ConnectInput(m_gOrCout.Output); }
public MultiBitAdder(int iSize) { Size = iSize; Input1 = new WireSet(Size); Input2 = new WireSet(Size); Output = new WireSet(Size); //your code here FA = new FullAdder[iSize]; Overflow = new Wire(); FA[0] = new FullAdder(); FA[0].ConnectInput1(Input1[0]); FA[0].ConnectInput2(Input2[0]); FA[0].CarryInput.Value = 0; Output[0].ConnectInput(FA[0].Output); for (int i = 1; i < iSize; i++) { FA[i] = new FullAdder(); FA[i].ConnectInput1(Input1[i]); FA[i].ConnectInput2(Input2[i]); FA[i].CarryInput.ConnectInput(FA[i - 1].CarryOutput); Output[i].ConnectInput(FA[i].Output); } Overflow.ConnectInput(FA[Size - 1].CarryOutput); }
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 //init the muxes Zx = new BitwiseMux(iSize); Zy = new BitwiseMux(iSize); nX = new BitwiseMux(iSize); nY = new BitwiseMux(iSize); f = new BitwiseMux(iSize); nO = new BitwiseMux(iSize); notX = new BitwiseNotGate(iSize); notY = new BitwiseNotGate(iSize); notOutput = new BitwiseNotGate(iSize); and = new BitwiseAndGate(iSize); fullAdder = new FullAdder(); WireSet zeros = new WireSet(iSize); for (int i = 0; i < zeros.Size; i++) { zeros[i].ConnectInput(Zero); } Zx.ConnectInput1(InputX); Zx.ConnectInput2(zeros); Zx.ConnectControl(ZeroX); /*for (int i = 0; i < zeros.Size; i++) * { * zeros[i].ConnectInput(Zero); * }*/ Zy.ConnectInput1(InputY); Zy.ConnectInput2(zeros); Zy.ConnectControl(ZeroY); nX.ConnectInput1(Zx.Output); notX.ConnectInput(Zx.Output); nX.ConnectInput2(notX.Output); nX.ConnectControl(NotX); nY.ConnectInput1(Zy.Output); notY.ConnectInput(Zy.Output); nY.ConnectInput2(notY.Output); nY.ConnectControl(NotY); and.ConnectInput1(nX.Output); and.ConnectInput2(nY.Output); WireSet addResult = new WireSet(iSize); fullAdder.ConnectInput1(nX.Output[0]); fullAdder.ConnectInput2(nY.Output[0]); Wire Co = fullAdder.CarryOutput; addResult[0].ConnectInput(fullAdder.Output); for (int i = 1; i < iSize; i++) { fullAdder = new FullAdder(); fullAdder.ConnectInput1(nX.Output[i]); fullAdder.ConnectInput2(nY.Output[i]); fullAdder.CarryInput.ConnectInput(Co); Co = new Wire(); Co.ConnectInput(fullAdder.CarryOutput); addResult[i].ConnectInput(fullAdder.Output); } f.ConnectInput1(and.Output); f.ConnectInput2(addResult); f.ConnectControl(F); nO.ConnectInput1(f.Output); notOutput.ConnectInput(f.Output); nO.ConnectInput2(notOutput.Output); nO.ConnectControl(NotOutput); Output = nO.Output; }
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); }
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(Size); var fx = new BitwiseMux(Size); var fAdder = new MultiBitAdder(Size); var fAnd = new BitwiseAndGate(Size); var notX = new BitwiseNotGate(Size); var notY = new BitwiseNotGate(Size); var notCheckzero = new BitwiseNotGate(Size); var zeroCheck = new MultiBitAndGate(Size); var nOut = new BitwiseMux(Size); var notOut = new BitwiseNotGate(Size); var nx = new BitwiseMux(Size); var ny = new BitwiseMux(Size); var zx = new BitwiseMux(Size); var zy = new BitwiseMux(Size); var wireX0 = new WireSet(iSize); var wireY0 = new WireSet(iSize); wireX0.Set2sComplement(0); wireY0.Set2sComplement(0); try { //zx// var zeroXWire = new WireSet(Size); zeroXWire.Set2sComplement(0); zx.ConnectInput1(InputX); zx.ConnectInput2(zeroXWire); zx.ConnectControl(ZeroX); } catch (Exception e) { Console.WriteLine("zx exp" + e.Message); } try { //nx// nx.ConnectInput1(zx.Output); notX.ConnectInput(zx.Output); nx.ConnectInput2(notX.Output); nx.ConnectControl(NotX); } catch (Exception e) { Console.WriteLine("nx exp" + e.Message); } try { //zy// var zeroYWire = new WireSet(Size); zeroYWire.Set2sComplement(0); zy.ConnectInput1(InputY); zy.ConnectInput2(zeroYWire); zy.ConnectControl(ZeroY); } catch (Exception e) { Console.WriteLine("zy exp" + e.Message); } try { //ny// ny.ConnectInput1(zy.Output); notY.ConnectInput(zy.Output); ny.ConnectInput2(notY.Output); ny.ConnectControl(NotY); } catch (Exception e) { Console.WriteLine("ny exp" + e.Message); } try { //f// fAdder.ConnectInput1(nx.Output); fAdder.ConnectInput2(ny.Output); fAnd.ConnectInput1(nx.Output); fAnd.ConnectInput2(ny.Output); fx.ConnectInput1(fAnd.Output); fx.ConnectInput2(fAdder.Output); fx.ConnectControl(F); } catch (Exception e) { Console.WriteLine("f exp" + e.Message); throw; } try { notOut.ConnectInput(fx.Output); nOut.ConnectInput1(fx.Output); nOut.ConnectInput2(notOut.Output); nOut.ConnectControl(NotOutput); /*********************************/ Output = nOut.Output; /*********************************/ } catch (Exception e) { Console.WriteLine("not Output exp" + e.Message); } try { //negative number check Negative = Output[Size - 1]; //Zero number check notCheckzero.ConnectInput(nOut.Output); zeroCheck.ConnectInput(notCheckzero.Output); Zero.ConnectInput(zeroCheck.Output); } catch (Exception e) { Console.WriteLine("Output info exp" + e.Message); throw; } }
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]); }
//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); }