private BitwiseMultiwayMux m_gJumpMux;//an example of a control unit compnent - a mux that controls whether a jump is made


        private void ConnectControls()
        {
            //1. connect control of mux 1 (selects entrance to register A)
            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)

            //4. connect ALU control bits
            m_gALU.ZeroX.ConnectInput(Instruction[C1]);
            m_gALU.NotX.ConnectInput(Instruction[C2]);
            m_gALU.ZeroY.ConnectInput(Instruction[C3]);
            m_gALU.NotY.ConnectInput(Instruction[C4]);
            m_gALU.F.ConnectInput(Instruction[C5]);
            m_gALU.NotOutput.ConnectInput(Instruction[C6]);
            //5. connect control to register D (very simple)
            and_D.ConnectInput1(Instruction[D2]);
            and_D.ConnectInput2(Instruction[Type]);
            m_rD.Load.ConnectInput(and_D.Output);
            //6. connect control to register A (a bit more complicated)
            not_A.ConnectInput(Instruction[Type]);
            or_A.ConnectInput1(not_A.Output);
            or_A.ConnectInput2(Instruction[D1]);
            m_rA.Load.ConnectInput(or_A.Output);
            //7. connect control to MemoryWrite
            and_MW.ConnectInput1(Instruction[D3]);
            and_MW.ConnectInput2(Instruction[Type]);
            MemoryWrite.ConnectInput(and_MW.Output);
            //8. create inputs for jump mux
            not_Zero.ConnectInput(m_gALU.Zero);
            not_Neg.ConnectInput(m_gALU.Negative);
            and_JMP.ConnectInput1(not_Zero.Output);
            and_JMP.ConnectInput2(not_Neg.Output);
            //not3.ConnectInput(m_gALU.Negative);
            or_JMP.ConnectInput2(m_gALU.Negative);
            or_JMP.ConnectInput1(m_gALU.Zero);
            //not4.ConnectInput(m_gALU.Zero);
            //or2.ConnectInput1(m_gALU.Zero);
            //or2.ConnectInput2(m_gALU.Negative);

            //9. connect jump mux (this is the most complicated part)
            m_gJumpMux = new BitwiseMultiwayMux(1, 3);
            J_0.ConnectInput(wi1);
            m_gJumpMux.Inputs[0][0].ConnectInput(J_0);
            JGT.ConnectInput(and_JMP.Output);
            m_gJumpMux.Inputs[1][0].ConnectInput(JGT);
            JEQ.ConnectInput(m_gALU.Zero);
            m_gJumpMux.Inputs[2][0].ConnectInput(JEQ);
            JGE.ConnectInput(not_Neg.Output);
            m_gJumpMux.Inputs[3][0].ConnectInput(JGE);
            JLT.ConnectInput(m_gALU.Negative);
            m_gJumpMux.Inputs[4][0].ConnectInput(JLT);
            JNE.ConnectInput(not_Zero.Output);
            m_gJumpMux.Inputs[5][0].ConnectInput(JNE);
            JLE.ConnectInput(or_JMP.Output);
            m_gJumpMux.Inputs[6][0].ConnectInput(JLE);
            wi2.Value = 1;
            J_1.ConnectInput(wi2);
            m_gJumpMux.Inputs[7][0].ConnectInput(J_1);
            and_JM2.ConnectInput1(Instruction[Type]);
            and_JM2.ConnectInput2(Instruction[J1]);
            and_JM1.ConnectInput1(Instruction[Type]);
            and_JM1.ConnectInput2(Instruction[J2]);
            and_JM0.ConnectInput1(Instruction[Type]);
            and_JM0.ConnectInput2(Instruction[J3]);
            JMP[2].ConnectInput(and_JM2.Output);
            JMP[1].ConnectInput(and_JM1.Output);
            JMP[0].ConnectInput(and_JM0.Output);
            m_gJumpMux.ConnectControl(JMP);
            //10. connect PC load control
            m_rPC.ConnectLoad(m_gJumpMux.Output[0]);
        }
Example #2
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);
        }