public override bool TestGate() { for (int k = 1; k >= 0; k--) { Control.Value = k; for (int i = 0; i < Math.Pow(2, Size); i++) { BitwiseDemux mgDemux = new BitwiseDemux(Size); WireSet ws = new WireSet(Size); ws.SetValue(i); mgDemux.ConnectInput(ws); mgDemux.ConnectControl(Control); for (int j = Size - 1; j >= 0; j--) { if (k == 0) { if (mgDemux.Output1[j].Value != ws[j].Value || mgDemux.Output2[j].Value != 0) { return(false); } } else if (mgDemux.Output1[j].Value != ws[j].Value || mgDemux.Output2[j].Value != 0) { return(false); } } } } return(true); }
// 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 override bool TestGate() { try { var ws1 = new WireSet(Size); for (int i = 0; i < Math.Pow(2, Size) - 1; i++) { ws1.SetValue(i); for (int j = 0; j < Math.Pow(2, Size) - 1; j++) { var mgOr = new BitwiseOrGate(Size); var ws2 = new WireSet(Size); ws2.SetValue(j); mgOr.ConnectInput1(ws1); mgOr.ConnectInput2(ws2); for (int k = 0; k < ws1.Size; k++) { if (mgOr.Output[j].Value != (ws1[j].Value | ws2[j].Value)) { return(false); } } } } } catch (Exception e) { Console.WriteLine(e.Message + " " + e.HelpLink); } return(true); }
public override bool TestGate() { var ws1 = new WireSet(Size); for (int i = 0; i < Math.Pow(2, Size); i++) { ws1.SetValue(i); for (int j = 0; j < Math.Pow(2, Size); j++) { var mgAnd = new BitwiseAndGate(Size); var ws2 = new WireSet(Size); ws2.SetValue(j); mgAnd.ConnectInput1(ws1); mgAnd.ConnectInput2(ws2); for (int k = 0; k < ws2.Size; k++) { if (mgAnd.Output[k].Value != (ws1[k].Value & ws2[k].Value)) { return(false); } } } } return(true); }
public MultiBitZero(int iSize) { Size = iSize; Input = new WireSet(Size); Output = new WireSet(Size); Output.SetValue(0); }
private static void TestWireSet_Value(WireSet wireSet, int value) { wireSet.SetValue(value); if (value != wireSet.GetValue()) { Console.WriteLine("bugbug wireset"); } }
public override bool TestGate() { WireSet ws1 = new WireSet(5); WireSet ws2 = new WireSet(5); ws1.SetValue(5); ws2.Set2sComplement(7); this.ConnectInput1(ws1); this.ConnectInput2(ws2); Console.WriteLine("TESTING Or..Is it true? :MULTI_BIT_ADDER " + this.ToString()); return(true); }
public override bool TestGate() { for (int j = 0; j < Math.Pow(2, Size); j++) { var mgNot = new BitwiseNotGate(Size); var ws = new WireSet(Size); ws.SetValue(j); mgNot.ConnectInput(ws); for (int k = ws.Size - 1; k >= 0; k--) { if (mgNot.Output[k].Value == ws[k].Value) { return(false); } } } return(true); }
public override bool TestGate() { try { for (int k = 1; k >= 0; k--) { ControlInput.Value = k; for (int i = 0; i < Math.Pow(2, Size); i++) { for (int j = 0; j < Math.Pow(2, Size); j++) { BitwiseMux mgMux = new BitwiseMux(Size); WireSet ws2 = new WireSet(Size); WireSet ws1 = new WireSet(Size); ws1.SetValue(i); ws2.SetValue(j); mgMux.ConnectInput1(ws1); mgMux.ConnectInput2(ws2); mgMux.ConnectControl(ControlInput); for (int f = Size - 1; f >= 0; f--) { if (k == 0) { if (mgMux.Output[f].Value == ws1[f].Value) { continue; } return(false); } else if (mgMux.Output[f].Value != ws2[f].Value) { return(false); } } } } } } catch (Exception e) { Console.WriteLine(e); } return(true); }
public override bool TestGate() { int wordBitsFilter = WordBitsFilter(); var wsFlags = new WireSet(6); int inputPermutationsCount = (int)Math.Pow(2, Size); int flagsPermutationsCount = (int)Math.Pow(2, wsFlags.Size); for (int i = 0; i < inputPermutationsCount; i++) { InputX.SetValue(i); for (int j = 0; j < inputPermutationsCount; j++) { InputY.SetValue(j); for (int k = 0; k < flagsPermutationsCount; k++) { wsFlags.SetValue(k); SetFlags(wsFlags); bool test = Test( wordBitsFilter, InputX.Get2sComplement(), InputY.Get2sComplement(), ZeroX.Value, NotX.Value, ZeroY.Value, NotY.Value, F.Value, NotOutput.Value ); if (!test) { return(false); } } } } return(true); }
public override bool TestGate() { WireSet ws = new WireSet(Size); WireSet ws2 = new WireSet(Size); MultiBitAdder mba; for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { mba = new MultiBitAdder(Size); ws.SetValue(i); ws2.SetValue(j); mba.Input1.ConnectInput(ws); mba.Input2.ConnectInput(ws2); if (mba.Output.GetValue() != (ws.GetValue() + ws2.GetValue())) { return(false); } } } return(true); }
static void Main(string[] args) { OrGate or = new OrGate(); XorGate xor = new XorGate(); AndGate and = new AndGate(); MuxGate mux = new MuxGate(); Demux demux = new Demux(); HalfAdder halfAdder = new HalfAdder(); FullAdder fullAdder = new FullAdder(); WireSet wireSet = new WireSet(9); BitwiseAndGate bwag = new BitwiseAndGate(2); BitwiseNotGate bwng = new BitwiseNotGate(3); BitwiseOrGate bwog = new BitwiseOrGate(2); BitwiseMux bwm = new BitwiseMux(2); BitwiseDemux bwd = new BitwiseDemux(2); MultiBitAndGate mbag = new MultiBitAndGate(4); MultiBitAdder mba = new MultiBitAdder(3); BitwiseMultiwayMux bwmwm = new BitwiseMultiwayMux(5, 4); BitwiseMultiwayDemux bwmwd = new BitwiseMultiwayDemux(4, 4); SingleBitRegister sbr = new SingleBitRegister(); MultiBitRegister mbr = new MultiBitRegister(4); if (!sbr.TestGate()) { Console.WriteLine("SingleBitRegisterbugbug"); } if (!mbr.TestGate()) { Console.WriteLine("MultiBitRegisterbugbug"); } ALU alu = new ALU(4); if (!alu.TestGate()) { Console.WriteLine("ALUbugbug"); } if (!bwmwd.TestGate()) { Console.WriteLine("BitwiseMultiwayDemuxbugbug"); } if (!bwmwm.TestGate()) { Console.WriteLine("BitwiseMultiwayMuxbugbug"); } if (!mba.TestGate()) { Console.WriteLine("MultiBitAdderbugbug"); } if (!mbag.TestGate()) { Console.WriteLine("MultiBitAndGatebugbug"); } if (!bwd.TestGate()) { Console.WriteLine("BitWiseDemuxbugbug"); } if (!bwm.TestGate()) { Console.WriteLine("BitWiseMuxbugbug"); } if (!bwog.TestGate()) { Console.WriteLine("BitWiseOrGatebugbug"); } if (!bwng.TestGate()) { Console.WriteLine("BitWiseNotGatebugbug"); } if (!bwag.TestGate()) { Console.WriteLine("BitWiseAndGatebugbug"); } wireSet.SetValue(137); wireSet.Set2sComplement(-32); if (!and.TestGate()) { Console.WriteLine("andbugbug"); } if (!or.TestGate()) { Console.WriteLine("orbugbug"); } if (!xor.TestGate()) { Console.WriteLine("xorbugbug"); } if (!mux.TestGate()) { Console.WriteLine("muxbugbug"); } if (!demux.TestGate()) { Console.WriteLine("demuxbugbug"); } if (!halfAdder.TestGate()) { Console.WriteLine("HAbugbug"); } if (!fullAdder.TestGate()) { Console.WriteLine("FAbugbug"); } Memory memory = new Memory(2, 6); if (!memory.TestGate()) { Console.WriteLine("Membugbug"); } Console.WriteLine("done"); Console.ReadLine(); }
static void Main(string[] args) { AndGate and = new AndGate(); OrGate or = new OrGate(); XorGate xor = new XorGate(); MuxGate mux = new MuxGate(); Demux demux = new Demux(); HalfAdder ha = new HalfAdder(); FullAdder fa = new FullAdder(); if (!and.TestGate()) { Console.WriteLine("bugbug"); } Console.WriteLine("done And"); if (!or.TestGate()) { Console.WriteLine("bugbug"); } Console.WriteLine("done Or"); if (!xor.TestGate()) { Console.WriteLine("bugbug"); } Console.WriteLine("done Xor"); if (!mux.TestGate()) { Console.WriteLine("bugbug"); } Console.WriteLine("done Mux"); if (!demux.TestGate()) { Console.WriteLine("bugbug"); } Console.WriteLine("done Demux"); if (!ha.TestGate()) { Console.WriteLine("bugbug"); } Console.WriteLine("done HalfAdder"); if (!fa.TestGate()) { Console.WriteLine("bugbug"); } Console.WriteLine("done FullAdder"); WireSet num = new WireSet(4); num.SetValue(6); Console.WriteLine(num.ToString()); Console.WriteLine(num.GetValue()); Console.WriteLine("trying 2's complement"); WireSet num2 = new WireSet(4); num2.Set2sComplement(6); Console.WriteLine(num2.Get2sComplement()); WireSet num3 = new WireSet(4); num3.Set2sComplement(-2); Console.WriteLine(num3.Get2sComplement()); BitwiseAndGate BWAnd = new BitwiseAndGate(3); BWAnd.TestGate(); BitwiseNotGate BWNot = new BitwiseNotGate(3); BWNot.TestGate(); BitwiseOrGate BWOr = new BitwiseOrGate(3); BWOr.TestGate(); BitwiseMux BWMux = new BitwiseMux(3); BWMux.TestGate(); BitwiseDemux BWDemux = new BitwiseDemux(3); BWDemux.TestGate(); MultiBitAndGate multiAnd = new MultiBitAndGate(3); multiAnd.TestGate(); MultiBitAdder multiAdd = new MultiBitAdder(5); multiAdd.TestGate(); BitwiseMultiwayMux multimux = new BitwiseMultiwayMux(8, 2); WireSet[] inp = new WireSet[4]; inp[0] = new WireSet(8); inp[0].Set2sComplement(1); multimux.ConnectInput(0, inp[0]); inp[1] = new WireSet(8); inp[1].Set2sComplement(2); multimux.ConnectInput(1, inp[1]); inp[2] = new WireSet(8); inp[2].Set2sComplement(3); multimux.ConnectInput(2, inp[2]); inp[3] = new WireSet(8); inp[3].Set2sComplement(4); multimux.ConnectInput(3, inp[3]); WireSet control = new WireSet(2); control.Set2sComplement(3); multimux.ConnectControl(control); multimux.TestGate(); BitwiseMultiwayDemux multidemux = new BitwiseMultiwayDemux(8, 1); ALU alu = new ALU(16); alu.TestGate(); SingleBitRegister sbr = new SingleBitRegister(); if (sbr.TestGate()) { Console.WriteLine("sbr IS OK"); } MultiBitRegister mbr = new MultiBitRegister(8); if (mbr.TestGate()) { Console.WriteLine("mbr IS OK"); } Memory mem = new Memory(3, 6); if (mem.TestGate()) { Console.WriteLine("mem IS OK"); } Console.ReadLine(); }
static void Main(string[] args) { //This is an example of a testing code that you should run for all the gates that you create // // //Create a gate // AndGate and = new AndGate(); // //Test that the unit testing works properly // if (!and.TestGate()) // Console.WriteLine("bugbug"); // // //test or gate // OrGate or = new OrGate(); // if (or.TestGate()) // Console.WriteLine("done or"); // //test xor gate // XorGate xor = new XorGate(); // if (xor.TestGate()) // Console.WriteLine("done xor"); // // MultiBitAndGate mbaGate = new MultiBitAndGate(4); // if (mbaGate.TestGate()) // Console.WriteLine("done mba"); // // MultiBitOrGate mboGate = new MultiBitOrGate(4); // if (mboGate.TestGate()) // Console.WriteLine("done mbo"); // // MuxGate mux = new MuxGate(); // if (mux.TestGate()) // Console.WriteLine("done mux"); // // Demux demux = new Demux(); // if (demux.TestGate()) // Console.WriteLine("done demux"); // // BitwiseAndGate bwAg = new BitwiseAndGate(4); // if (bwAg.TestGate()) // Console.WriteLine("done bwAg"); // // BitwiseNotGate bwNg = new BitwiseNotGate(4); // if (bwNg.TestGate()) // Console.WriteLine("done bwNg"); //// // BitwiseOrGate bwOg = new BitwiseOrGate(4); // if (bwOg.TestGate()) // Console.WriteLine("done bwOg"); // // // WireSet ws = new WireSet(4); // ws.SetValue(8); // Console.WriteLine(ws.ToString()); //// // BitwiseMux bwMux = new BitwiseMux(4); // if (bwMux.TestGate()) // Console.WriteLine("done bwMux"); // // BitwiseDemux bwDemux = new BitwiseDemux(4); // if (bwDemux.TestGate()) // Console.WriteLine("done bwDemux"); // // BitwiseMultiwayMux bwMwMux = new BitwiseMultiwayMux(3,3); // if (bwMwMux.TestGate()) // Console.WriteLine("done bwMwMux"); OrGate or = new OrGate(); XorGate xor = new XorGate(); AndGate and = new AndGate(); MuxGate mux = new MuxGate(); Demux demux = new Demux(); HalfAdder halfAdder = new HalfAdder(); FullAdder fullAdder = new FullAdder(); WireSet wireSet = new WireSet(9); BitwiseAndGate bwag = new BitwiseAndGate(2); BitwiseNotGate bwng = new BitwiseNotGate(3); BitwiseOrGate bwog = new BitwiseOrGate(2); BitwiseMux bwm = new BitwiseMux(2); BitwiseDemux bwd = new BitwiseDemux(2); MultiBitAndGate mbag = new MultiBitAndGate(4); MultiBitAdder mba = new MultiBitAdder(3); BitwiseMultiwayMux bwmwm = new BitwiseMultiwayMux(5, 4); BitwiseMultiwayDemux bwmwd = new BitwiseMultiwayDemux(4, 4); SingleBitRegister sbr = new SingleBitRegister(); MultiBitRegister mbr = new MultiBitRegister(4); wireSet.SetValue(137); wireSet.Set2sComplement(-32); if (halfAdder.TestGate()) { Console.WriteLine("HAbugbug"); } if (fullAdder.TestGate()) { Console.WriteLine("FAbugbug"); } if (mba.TestGate()) { Console.WriteLine("MultiBitAdderbugbug"); } ALU alu = new ALU(16); if (alu.TestGate()) { Console.WriteLine("ALU bugbug"); } Console.WriteLine("FINISH HIM"); }
public override bool TestGate() { ALU al; WireSet[] inputs = new WireSet[2]; WireSet[] solution = new WireSet[18]; WireSet[] all = new WireSet[6]; for (int i = 0; i < all.Length; i++) { all[i] = new WireSet(18); } WireSet wsTemp = new WireSet(18); WireSet wsTemp2 = new WireSet(Size); wsTemp.SetValue(240288); all[0].ConnectInput(wsTemp); wsTemp = new WireSet(18); wsTemp.SetValue(109481); all[1].ConnectInput(wsTemp); wsTemp = new WireSet(18); wsTemp.SetValue(251200); all[2].ConnectInput(wsTemp); wsTemp = new WireSet(18); wsTemp.SetValue(87493); all[3].ConnectInput(wsTemp); wsTemp = new WireSet(18); wsTemp.SetValue(231420); all[4].ConnectInput(wsTemp); wsTemp = new WireSet(18); wsTemp.SetValue(73613); all[5].ConnectInput(wsTemp); for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { for (int f = 0; f < solution.Length; f++) { solution[f] = new WireSet(Size); } inputs[0] = new WireSet(Size); inputs[1] = new WireSet(Size); inputs[0].SetValue(i); inputs[1].SetValue(j); wsTemp2 = new WireSet(Size); wsTemp2.SetValue(0); solution[0].ConnectInput(wsTemp2); wsTemp2 = new WireSet(Size); wsTemp2.SetValue(1); solution[1].ConnectInput(wsTemp2); wsTemp2 = new WireSet(Size); wsTemp2.Set2sComplement(-1); solution[2].ConnectInput(wsTemp2); solution[3].ConnectInput(inputs[0]); solution[4].ConnectInput(inputs[1]); BitwiseNotGate bwng = new BitwiseNotGate(Size); bwng.ConnectInput(inputs[0]); solution[5].ConnectInput(bwng.Output); bwng = new BitwiseNotGate(Size); bwng.ConnectInput(inputs[1]); solution[6].ConnectInput(bwng.Output); wsTemp2 = new WireSet(Size); wsTemp2.SetValue(inputs[0].GetValue() * -1); solution[7].ConnectInput(wsTemp2); wsTemp2 = new WireSet(Size); wsTemp2.SetValue(inputs[1].GetValue() * -1); solution[8].ConnectInput(wsTemp2); wsTemp2 = new WireSet(Size); wsTemp2.SetValue(inputs[0].GetValue() + 1); solution[9].ConnectInput(wsTemp2); wsTemp2 = new WireSet(Size); wsTemp2.SetValue(inputs[1].GetValue() + 1); solution[10].ConnectInput(wsTemp2); wsTemp2 = new WireSet(Size); wsTemp2.SetValue(inputs[0].GetValue() - 1); solution[11].ConnectInput(wsTemp2); wsTemp2 = new WireSet(Size); wsTemp2.SetValue(inputs[1].GetValue() - 1); solution[12].ConnectInput(wsTemp2); wsTemp2 = new WireSet(Size); wsTemp2.SetValue(inputs[0].GetValue() + inputs[1].GetValue()); solution[13].ConnectInput(wsTemp2); wsTemp2 = new WireSet(Size); wsTemp2.SetValue(inputs[0].GetValue() - inputs[1].GetValue()); solution[14].ConnectInput(wsTemp2); wsTemp2 = new WireSet(Size); wsTemp2.SetValue(inputs[1].GetValue() - inputs[0].GetValue()); solution[15].ConnectInput(wsTemp2); BitwiseOrGate bwog = new BitwiseOrGate(Size); BitwiseAndGate bwag = new BitwiseAndGate(Size); bwog.ConnectInput1(inputs[0]); bwog.ConnectInput2(inputs[1]); bwag.ConnectInput1(inputs[0]); bwag.ConnectInput2(inputs[1]); solution[16].ConnectInput(bwag.Output); solution[17].ConnectInput(bwog.Output); for (int k = 0; k < 18; k++) { al = new ALU(Size); al.InputX.ConnectInput(inputs[0]); al.InputY.ConnectInput(inputs[1]); al.ZeroX.Value = all[0][17 - k].Value; al.NotX.Value = all[1][17 - k].Value; al.ZeroY.Value = all[2][17 - k].Value; al.NotY.Value = all[3][17 - k].Value; al.F.Value = all[4][17 - k].Value; al.NotOutput.Value = all[5][17 - k].Value; if (al.Output.ToString() != solution[k].ToString()) { return(false); } } } } return(true); }