Beispiel #1
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);
 }
Beispiel #2
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;
            }
        }
Beispiel #3
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);
        }
Beispiel #4
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);
            }
        }
Beispiel #5
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;
        }
Beispiel #6
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();
            }
        }
Beispiel #7
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++;
            }
        }
Beispiel #8
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);
            }
        }
Beispiel #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);
        }