Esempio n. 1
0
        private void ConnectControls()
        {
            or       = new OrGate();
            muxArray = new MuxGate[9];
            NotGate not = new NotGate();

            JGT      = new AndGate();
            JGE      = new OrGate();
            JLE      = new OrGate();
            JNE      = new NotGate();
            notArray = new NotGate[2];

            for (int i = 0; i < notArray.Length; i++)
            {
                notArray[i] = new NotGate();
            }

            m_gJumpMux = new BitwiseMultiwayMux(1, 3);
            jump       = new WireSet(3);

            andForPCLoad = new AndGate();
            Wire PCLoad = new Wire();

            //1.
            m_gAMux.ConnectControl(Instruction[Type]);

            //2. connect control to mux 2 (selects A or M entrance to the ALU)
            m_gMAMux.ConnectControl(Instruction[A]);

            //3. consider all instruction bits only if C type instruction (MSB of instruction is 1)
            for (int i = 0; i < muxArray.Length; i++)
            {
                muxArray[i] = new MuxGate();
                muxArray[i].ConnectInput1(new Wire());
                muxArray[i].ConnectInput2(Instruction[i + 3]);
                muxArray[i].ConnectControl(Instruction[Type]);
            }
            //4. connect ALU control bits
            m_gALU.ZeroX.ConnectInput(muxArray[C1 - 3].Output);
            m_gALU.NotX.ConnectInput(muxArray[C2 - 3].Output);
            m_gALU.ZeroY.ConnectInput(muxArray[C3 - 3].Output);
            m_gALU.NotY.ConnectInput(muxArray[C4 - 3].Output);
            m_gALU.F.ConnectInput(muxArray[C5 - 3].Output);
            m_gALU.NotOutput.ConnectInput(muxArray[C6 - 3].Output);

            //5. connect control to register D (very simple)
            m_rD.Load.ConnectInput(muxArray[D2 - 3].Output);

            //6. connect control to register A (a bit more complicated)
            not.ConnectInput(Instruction[Type]);
            or.ConnectInput1(not.Output);
            or.ConnectInput2(muxArray[D1 - 3].Output);
            m_rA.Load.ConnectInput(or.Output);

            //7. connect control to MemoryWrite
            MemoryWrite.ConnectInput(muxArray[D3 - 3].Output);
            //8. create inputs for jump mux
            notArray[0].ConnectInput(m_gALU.Zero);
            notArray[1].ConnectInput(m_gALU.Negative);
            //JGT:
            JGT.ConnectInput1(notArray[0].Output);
            JGT.ConnectInput2(notArray[1].Output);
            //JGE:
            JGE.ConnectInput1(m_gALU.Zero);
            JGE.ConnectInput2(notArray[1].Output);
            //JNE:
            JNE.ConnectInput(notArray[0].Output);
            //JLE:
            JLE.ConnectInput1(m_gALU.Zero);
            JLE.ConnectInput2(m_gALU.Negative);


            WireSet JGTOut = new WireSet(1);
            WireSet JEQOut = new WireSet(1);
            WireSet JLTOut = new WireSet(1);
            WireSet JGEOut = new WireSet(1);
            WireSet JNEOut = new WireSet(1);
            WireSet JLEOut = new WireSet(1);

            JGTOut[0].ConnectInput(JGT.Output);
            JEQOut[0].ConnectInput(m_gALU.Zero);
            JLTOut[0].ConnectInput(m_gALU.Negative);
            JGEOut[0].ConnectInput(JGE.Output);
            JNEOut[0].ConnectInput(JNE.Output);
            JLEOut[0].ConnectInput(JLE.Output);

            //9. connect jump mux (this is the most complicated part)
            jump[0].ConnectInput(Instruction[J3]);
            jump[1].ConnectInput(Instruction[J2]);
            jump[2].ConnectInput(Instruction[J1]);
            m_gJumpMux.ConnectControl(jump);
            m_gJumpMux.ConnectInput(0, new WireSet(1));
            m_gJumpMux.ConnectInput(1, JGTOut);
            m_gJumpMux.ConnectInput(2, JEQOut);
            m_gJumpMux.ConnectInput(3, JGEOut);
            m_gJumpMux.ConnectInput(4, JLTOut);
            m_gJumpMux.ConnectInput(5, JNEOut);
            m_gJumpMux.ConnectInput(6, JLEOut);
            m_gJumpMux.Inputs[7].Value = 1;
            //10. connect PC load control
            andForPCLoad.ConnectInput1(m_gJumpMux.Output[0]);
            andForPCLoad.ConnectInput2(Instruction[Type]);
            m_rPC.ConnectLoad(andForPCLoad.Output);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            WireSet ws  = new WireSet(9);
            WireSet ws2 = new WireSet(9);
            WireSet ws3 = new WireSet(9);
            OrGate  or  = new OrGate();

            XorGate xor = new XorGate();

            MultiBitAndGate mbag3 = new MultiBitAndGate(3);
            MultiBitAndGate mbag4 = new MultiBitAndGate(4);
            MultiBitAndGate mbag5 = new MultiBitAndGate(5);
            MultiBitAndGate mbag6 = new MultiBitAndGate(6);
            MultiBitAndGate mbag7 = new MultiBitAndGate(7);
            MultiBitAndGate mbag8 = new MultiBitAndGate(8);

            MultiBitOrGate mbog3 = new MultiBitOrGate(3);
            MultiBitOrGate mbog4 = new MultiBitOrGate(4);
            MultiBitOrGate mbog5 = new MultiBitOrGate(5);
            MultiBitOrGate mbog6 = new MultiBitOrGate(6);
            MultiBitOrGate mbog7 = new MultiBitOrGate(7);
            MultiBitOrGate mbog8 = new MultiBitOrGate(8);

            MuxGate mg  = new MuxGate();
            Demux   dmg = new Demux();

            BitwiseOrGate bwog0 = new BitwiseOrGate(0);
            BitwiseOrGate bwog1 = new BitwiseOrGate(1);
            BitwiseOrGate bwog2 = new BitwiseOrGate(2);
            BitwiseOrGate bwog3 = new BitwiseOrGate(3);
            BitwiseOrGate bwog4 = new BitwiseOrGate(4);
            BitwiseOrGate bwog5 = new BitwiseOrGate(5);
            BitwiseOrGate bwog6 = new BitwiseOrGate(6);
            BitwiseOrGate bwog7 = new BitwiseOrGate(7);

            BitwiseAndGate bwag2 = new BitwiseAndGate(2);
            BitwiseAndGate bwag3 = new BitwiseAndGate(3);
            BitwiseAndGate bwag4 = new BitwiseAndGate(4);

            BitwiseNotGate bwng2 = new BitwiseNotGate(2);
            BitwiseNotGate bwng3 = new BitwiseNotGate(3);
            BitwiseNotGate bwng4 = new BitwiseNotGate(4);

            BitwiseDemux bwdm2 = new BitwiseDemux(2);
            BitwiseDemux bwdm3 = new BitwiseDemux(3);
            BitwiseDemux bwdm4 = new BitwiseDemux(4);

            BitwiseMux bwmx2 = new BitwiseMux(2);
            BitwiseMux bwmx3 = new BitwiseMux(3);
            BitwiseMux bwmx4 = new BitwiseMux(4);

            BitwiseMultiwayMux   bwmwm  = new BitwiseMultiwayMux(3, 3);
            BitwiseMultiwayDemux bwmwdm = new BitwiseMultiwayDemux(3, 3);

            HalfAdder     ha  = new HalfAdder();
            FullAdder     fa  = new FullAdder();
            MultiBitAdder mba = new MultiBitAdder(4);
            ALU           alu = new ALU(4);

            System.Console.WriteLine(or.TestGate().ToString());

            System.Console.WriteLine(xor.TestGate().ToString());

            System.Console.WriteLine(mbag3.TestGate().ToString());
            System.Console.WriteLine(mbag4.TestGate().ToString());
            System.Console.WriteLine(mbag5.TestGate().ToString());
            System.Console.WriteLine(mbag6.TestGate().ToString());
            System.Console.WriteLine(mbag7.TestGate().ToString());
            System.Console.WriteLine(mbag8.TestGate().ToString());

            System.Console.WriteLine(mbog3.TestGate().ToString());
            System.Console.WriteLine(mbog4.TestGate().ToString());
            System.Console.WriteLine(mbog5.TestGate().ToString());
            System.Console.WriteLine(mbog6.TestGate().ToString());
            System.Console.WriteLine(mbog7.TestGate().ToString());
            System.Console.WriteLine(mbog8.TestGate().ToString());

            System.Console.WriteLine(mg.TestGate().ToString());
            System.Console.WriteLine(dmg.TestGate().ToString());

            System.Console.WriteLine(bwag2.TestGate().ToString());
            System.Console.WriteLine(bwag3.TestGate().ToString());
            System.Console.WriteLine(bwag4.TestGate().ToString());

            System.Console.WriteLine(bwog0.TestGate().ToString());
            System.Console.WriteLine(bwog1.TestGate().ToString());
            System.Console.WriteLine(bwog2.TestGate().ToString());
            System.Console.WriteLine(bwog3.TestGate().ToString());
            System.Console.WriteLine(bwog4.TestGate().ToString());
            System.Console.WriteLine(bwog5.TestGate().ToString());
            System.Console.WriteLine(bwog6.TestGate().ToString());
            System.Console.WriteLine(bwog7.TestGate().ToString());

            ws.Set2sComplement(-5);
            System.Console.WriteLine(ws.Get2sComplement().ToString());
            int test  = 0;
            int test2 = 0;

            for (int i = 1; i < 50; i++)
            {
                ws2.SetValue(i);
                if (ws2.GetValue() != i)
                {
                    test = 10;
                }
            }
            for (int i = -34; i < 50; i++)
            {
                ws3.Set2sComplement(i);
                if (ws3.Get2sComplement() != i)
                {
                    test2 = 10;
                }
            }
            System.Console.WriteLine(test);
            System.Console.WriteLine(test2);

            System.Console.WriteLine(bwng2.TestGate().ToString());
            System.Console.WriteLine(bwng3.TestGate().ToString());
            System.Console.WriteLine(bwng4.TestGate().ToString());

            System.Console.WriteLine(bwdm2.TestGate().ToString());
            System.Console.WriteLine(bwdm3.TestGate().ToString());
            System.Console.WriteLine(bwdm4.TestGate().ToString());

            System.Console.WriteLine(bwmx2.TestGate().ToString());
            System.Console.WriteLine(bwmx3.TestGate().ToString());
            System.Console.WriteLine(bwmx4.TestGate().ToString());

            System.Console.WriteLine(bwmwm.TestGate().ToString());

            System.Console.WriteLine(bwmwdm.TestGate().ToString());

            System.Console.WriteLine(ha.TestGate().ToString());
            System.Console.WriteLine(fa.TestGate().ToString());
            System.Console.WriteLine(mba.TestGate().ToString());

            System.Console.WriteLine(alu.TestGate().ToString());
        }