Ejemplo n.º 1
0
        // 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);


        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        // 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);
        }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
        //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);
            }
        }
Ejemplo n.º 7
0
        //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);
        }
        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]);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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();
        }
Ejemplo n.º 11
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();
        }
Ejemplo n.º 12
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");
        }
Ejemplo n.º 13
0
        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];*/
        }
Ejemplo n.º 14
0
        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;
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        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);

            zx   = new BitwiseMux(Size);
            zy   = new BitwiseMux(Size);
            nx   = new BitwiseMux(Size);
            ny   = new BitwiseMux(Size);
            fx   = new BitwiseMux(Size);
            nOut = new BitwiseMux(Size);

            notX         = new BitwiseNotGate(Size);
            notY         = new BitwiseNotGate(Size);
            notOut       = new BitwiseNotGate(Size);
            notCheckzero = new BitwiseNotGate(Size);

            fAdder = new MultiBitAdder(Size);
            fAnd   = new BitwiseAndGate(Size);

            negCheck  = new MultiBitAdder(Size);
            zeroCheck = new MultiBitAndGate(Size);

            //zx//
            WireSet zeroXWire = new WireSet(Size);

            zx.ConnectInput1(InputX);
            zx.ConnectInput2(zeroXWire);
            zx.ConnectControl(ZeroX);

            //nx//

            nx.ConnectInput1(zx.Output);
            notX.ConnectInput(zx.Output);
            nx.ConnectInput2(notX.Output);
            nx.ConnectControl(NotX);

            //zy//
            WireSet zeroYWire = new WireSet(Size);

            zy.ConnectInput1(InputY);
            zy.ConnectInput2(zeroYWire);
            zy.ConnectControl(ZeroY);

            //ny//

            ny.ConnectInput1(zy.Output);
            notY.ConnectInput(zy.Output);
            ny.ConnectInput2(notY.Output);
            ny.ConnectControl(NotY);

            //f//
            fAnd.ConnectInput1(nx.Output);
            fAnd.ConnectInput2(ny.Output);
            fAdder.ConnectInput1(nx.Output);
            fAdder.ConnectInput2(ny.Output);
            fx.ConnectInput1(fAnd.Output);
            fx.ConnectInput2(fAdder.Output);
            fx.ConnectControl(F);

            //not Outpot
            nOut.ConnectInput1(fx.Output);
            notOut.ConnectInput(fx.Output);
            nOut.ConnectInput2(notOut.Output);
            nOut.ConnectControl(NotOutput);


            Output = nOut.Output;


            //negative number check
            negCheck.ConnectInput1(nOut.Output);
            negCheck.ConnectInput2(nOut.Output);
            Negative = negCheck.Overflow;

            //Zero number check
            notCheckzero.ConnectInput(nOut.Output);
            zeroCheck.ConnectInput(notCheckzero.Output);
            Zero = zeroCheck.Output;
        }
Ejemplo n.º 18
0
        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;
            }
        }
Ejemplo n.º 19
0
        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
            muxZeroX  = new BitwiseMux(Size);
            muxZeroY  = new BitwiseMux(Size);
            muxNegX   = new BitwiseMux(Size);
            muxNegY   = new BitwiseMux(Size);
            muxFunc   = new BitwiseMux(Size);
            muxNegOut = new BitwiseMux(Size);
            mbAdder   = new MultiBitAdder(Size);
            bwAnd     = new BitwiseAndGate(Size);
            mbOr      = new MultiBitOrGate(Size);
            bwNot1    = new BitwiseNotGate(Size);
            bwNot2    = new BitwiseNotGate(Size);
            bwNot3    = new BitwiseNotGate(Size);
            zeroWS    = new WireSet(Size);
            negAnd    = new AndGate();
            notBit    = new Wire();
            not1      = new NotGate();

            // Zero X
            muxZeroX.Input1.ConnectInput(InputX);
            muxZeroX.Input2.ConnectInput(zeroWS);
            muxZeroX.ConnectControl(ZeroX);

            // Not X
            bwNot1.ConnectInput(muxZeroX.Output);
            muxNegX.Input1.ConnectInput(muxZeroX.Output);
            muxNegX.Input2.ConnectInput(bwNot1.Output);
            muxNegX.ConnectControl(NotX);

            // Zero Y
            muxZeroY.Input1.ConnectInput(InputY);
            muxZeroY.Input2.ConnectInput(zeroWS);
            muxZeroY.ConnectControl(ZeroY);

            // Not Y
            bwNot2.ConnectInput(muxZeroY.Output);
            muxNegY.Input1.ConnectInput(muxZeroY.Output);
            muxNegY.Input2.ConnectInput(bwNot2.Output);
            muxNegY.ConnectControl(NotY);

            // Func
            mbAdder.ConnectInput1(muxNegX.Output);
            mbAdder.ConnectInput2(muxNegY.Output);
            bwAnd.Input1.ConnectInput(muxNegX.Output);
            bwAnd.Input2.ConnectInput(muxNegY.Output);
            muxFunc.Input1.ConnectInput(bwAnd.Output);
            muxFunc.Input2.ConnectInput(mbAdder.Output);
            muxFunc.ConnectControl(F);

            // Not Output
            bwNot3.ConnectInput(muxFunc.Output);
            muxNegOut.Input1.ConnectInput(muxFunc.Output);
            muxNegOut.Input2.ConnectInput(bwNot3.Output);
            muxNegOut.ConnectControl(NotOutput);

            // Zero
            mbOr.ConnectInput(muxNegOut.Output);
            not1.ConnectInput(mbOr.Output);
            Zero.Value = not1.Output.Value;

            // Negative
            notBit.Value = 1;
            negAnd.Input1.ConnectInput(notBit);
            negAnd.Input2.ConnectInput(muxNegOut.Output[muxNegOut.Size - 1]);

            // Output
            //Output = bwAnd.Output;
            Output = muxNegOut.Output;
        }