Exemplo n.º 1
0
 private static void InitializeMuxGates(CompleteBinaryTree <MuxGate> muxGates)
 {
     for (int i = 0; i < muxGates.ItemsCount; i++)
     {
         muxGates[i] = new MuxGate();
     }
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
        private void ConnectInputs(CompleteBinaryTree <MuxGate> muxGates)
        {
            int iInput = 0;

            foreach (var itemIndexPair in muxGates.GetDepthEnumerator(muxGates.Height))
            {
                MuxGate muxGate = itemIndexPair.Item;
                muxGate.ConnectInput1(Inputs[iInput]);
                muxGate.ConnectInput2(Inputs[iInput + 1]);
                muxGate.ConnectControl(Control[0]);

                iInput += 2;
            }
        }
Exemplo n.º 4
0
        public SingleBitRegister()
        {
            Input = new Wire();
            Load  = new Wire();
            //your code here

            Output     = new Wire();
            m_flipFlop = new DFlipFlopGate();
            m_mux      = new MuxGate();
            m_mux.ConnectInput1(m_flipFlop.Output);
            m_mux.ConnectInput2(Input);
            m_mux.ConnectControl(Load);
            m_flipFlop.ConnectInput(m_mux.Output);
            Output.ConnectInput(m_flipFlop.Output);
        }
Exemplo n.º 5
0
        // checks each corisponding bit of the 2 inputs and making mux operation on them
        // and connects the output
        public BitwiseMux(int iSize)
            : base(iSize)
        {
            ControlInput = new Wire();

            for (int bit = 0; bit < Size; bit++)
            {
                mux_operation = new MuxGate();
                mux_operation.ConnectControl(ControlInput);
                mux_operation.ConnectInput1(Input1[bit]);
                mux_operation.ConnectInput2(Input2[bit]);

                Output[bit].ConnectInput(mux_operation.Output);
            }
        }
Exemplo n.º 6
0
        public BitwiseMux(int iSize)
            : base(iSize)
        {
            ControlInput = new Wire();
            MuxGate[] mgMux = new MuxGate[iSize];

            for (int i = 0; i < iSize; i++)
            {
                mgMux[i] = new MuxGate();
                mgMux[i].ConnectControl(ControlInput);
                mgMux[i].ConnectInput1(Input1[i]);
                mgMux[i].ConnectInput2(Input2[i]);
                Output[i].ConnectInput(mgMux[i].Output);
            }
        }
Exemplo n.º 7
0
        public SingleBitRegister()
        {
            Input = new Wire();
            Load  = new Wire();
            //your code here
            var gFlipFlop = new DFlipFlopGate();
            var gMux      = new MuxGate();

            gMux.ConnectInput1(Input);
            gMux.ConnectControl(Load);
            gMux.ConnectInput2(gFlipFlop.Output);

            gFlipFlop.ConnectInput(gMux.Output);
            Output = gFlipFlop.Output;
        }
Exemplo n.º 8
0
        public BitwiseMux(int iSize)
            : base(iSize)
        {
            ControlInput = new Wire();
            mux          = new MuxGate();

            for (int i = 0; i < Size; i++)
            {
                mux.ConnectInput1(Input1[i]);
                mux.ConnectInput2(Input2[i]);
                mux.ConnectControl(ControlInput);

                Output[i].ConnectInput(mux.Output);
                mux = new MuxGate();
            }
        }
Exemplo n.º 9
0
        private void BuildMuxGatesTree(CompleteBinaryTree <MuxGate> muxGates)
        {
            int iControl = 1;

            for (int depth = muxGates.Height - 1; depth >= 0; depth--)
            {
                foreach (var itemIndexPair in muxGates.GetDepthEnumerator(depth))
                {
                    int     index = itemIndexPair.Index;
                    MuxGate gate  = itemIndexPair.Item;
                    gate.ConnectInput1(muxGates.LeftChild(index).Output);
                    gate.ConnectInput2(muxGates.RightChild(index).Output);
                    gate.ConnectControl(Control[iControl]);
                }

                iControl++;
            }
        }
Exemplo n.º 10
0
        public BitwiseMux(int iSize)
            : base(iSize)
        {
            ControlInput = new Wire();
            //your code here

            m_gates = new MuxGate[Size];
            for (int i = 0; i < Size; i++)
            {
                var gate = new MuxGate();
                m_gates[i] = gate;

                gate.ConnectControl(ControlInput);
                gate.ConnectInput1(Input1[i]);
                gate.ConnectInput2(Input2[i]);
                Output[i].ConnectInput(gate.Output);
            }
        }
Exemplo n.º 11
0
        public BitwiseMux(int iSize)
            : base(iSize)
        {
            ControlInput = new Wire();
            //your code here
            m_gMux = new MuxGate[iSize];

            WireSet ws_resault = new WireSet(iSize);

            //your code here
            for (int i = 0; i < iSize; i++)
            {
                m_gMux[i] = new MuxGate();
                m_gMux[i].ConnectInput1(Input1[i]);
                m_gMux[i].ConnectInput2(Input2[i]);
                m_gMux[i].ConnectControl(ControlInput);

                ws_resault[i].ConnectInput(m_gMux[i].Output);
            }
            Output.ConnectInput(ws_resault);
        }
Exemplo n.º 12
0
        public override bool TestGate()
        {
            BitwiseMux bwmx;
            MuxGate    m_gLocalMux;

            Wire w_local = new Wire();

            for (int l = 0; l < 2; l++)
            {
                w_local.Value = l;
                for (int j = 0; j < Math.Pow(2, Size); j++)
                {
                    bwmx = new BitwiseMux(Size);
                    bwmx.ConnectInput1(InitTestVariables(j));
                    bwmx.ConnectInput2(InitRandTestVar(Size));
                    bwmx.ConnectControl(w_local);

                    for (int i = 0; i < Size; i++)
                    {
                        m_gLocalMux = new MuxGate();
                        m_gLocalMux.ConnectInput1(bwmx.Input1[i]);
                        m_gLocalMux.ConnectInput2(bwmx.Input2[i]);
                        m_gLocalMux.ConnectControl(w_local);
                        if (bwmx.Input1[i].Value == bwmx.Input2[i].Value && bwmx.Input2[i].Value == 1)
                        {
                            if (m_gLocalMux.Output.Value != bwmx.Output[i].Value)
                            {
                                return(false);
                            }
                        }
                    }
                    // UNCOMMENT THIS LINES TO SEE THE DEBUG PRINT
                    //System.Console.WriteLine("    Testing input1 " + " -> " + WStoString(bwmx.Input1));
                    //System.Console.WriteLine("    Testing input2 " + " -> " + WStoString(bwmx.Input2));
                    //System.Console.WriteLine("    Testing control" + " -> " + bwmx.ControlInput);
                    //System.Console.WriteLine("    Testing output " + " -> " + WStoString(bwmx.Output));
                }
            }
            return(true);
        }
Exemplo n.º 13
0
        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();
        }
Exemplo n.º 14
0
        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();
        }
Exemplo n.º 15
0
        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");
        }