Пример #1
0
        public override bool TestGate()
        {
            MultiBitOrGate mbog;

            int outCome;

            for (int j = 0; j < Math.Pow(2, m_wsInput.Size); j++)
            {
                outCome = 0;
                mbog    = new MultiBitOrGate(m_wsInput.Size);
                mbog.m_wsInput.ConnectInput(InitTestVariables(j));
                for (int i = 0; i < mbog.m_wsInput.Size; i++)
                {
                    if (mbog.m_wsInput[i].Value == 1)
                    {
                        outCome = 1;
                        break;
                    }
                }
                // UNCOMMENT THIS LINE TO SEE THE DEBUG PRINT
                //System.Console.WriteLine("    Testing input " + Convert.ToString(j, 2).PadLeft(m_wsInput.Size, '0') + " -> " + mbog.Output.Value.ToString() + " , " + outCome.ToString());
                if (outCome != mbog.Output.Value)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #2
0
        public MuxGate()
        {
            ControlInput = new Wire();

            //Init the variables
            m_gAnd1 = new AndGate();
            m_gAnd2 = new AndGate();
            m_gAnd3 = new AndGate();
            m_gNot  = new NotGate();
            m_gmOr  = new MultiBitOrGate(3);
            m_ws    = new WireSet(3);

            //Connect the wires
            m_gNot.ConnectInput(ControlInput);
            m_gAnd1.ConnectInput1(Input1);
            m_gAnd1.ConnectInput2(Input2);
            m_gAnd2.ConnectInput1(Input2);
            m_gAnd2.ConnectInput2(ControlInput);
            m_gAnd3.ConnectInput1(Input1);
            m_gAnd3.ConnectInput2(m_gNot.Output);
            m_ws[0].ConnectInput(m_gAnd1.Output);
            m_ws[1].ConnectInput(m_gAnd2.Output);
            m_ws[2].ConnectInput(m_gAnd3.Output);
            m_gmOr.ConnectInput(m_ws);
            Output = m_gmOr.Output;
        }
Пример #3
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
            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]);
        }
Пример #4
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;
        }