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]); }