Ejemplo n.º 1
0
        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]);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
0
Archivo: CPU16.cs Proyecto: boaz23/ECS
 private void InitializeJumpMux()
 {
     m_gJumpMux = new BitwiseMultiwayMux(SINGLE_BIT_SIZE, JUMP_CONTROLS_COUNT);
 }
Ejemplo n.º 5
0
        private void ConnectControls()
        {
            //1. connect control of mux 1 (selects entrance to register A)

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

            //2. connect control to mux 2 (selects A or M entrance to the ALU)

            m_gMAMux.ConnectControl(Instruction[A]);  //  a/m

            //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 = new AndGate();
            and.ConnectInput1(Instruction[Type]);
            and.ConnectInput2(Instruction[D2]);
            m_rD.Load.ConnectInput(and.Output);


            //6. connect control to register A (a bit more complicated)
            orOfA = new OrGate(); // shortcut for what we did in lesson "instead using and & not gates"

            // to implement as in lecture
            andOfA = new AndGate();
            notOfA = new NotGate();
            notOfA.ConnectInput(Instruction[Type]);
            andOfA.ConnectInput1(Instruction[Type]);
            andOfA.ConnectInput2(Instruction[D1]);
            orOfA.ConnectInput1(andOfA.Output);
            orOfA.ConnectInput2(notOfA.Output);
            m_rA.Load.ConnectInput(orOfA.Output);
            //7. connect control to MemoryWritea
            andOfMemoryWrite = new AndGate();
            andOfMemoryWrite.ConnectInput1(Instruction[Type]);
            andOfMemoryWrite.ConnectInput2(Instruction[D3]);
            MemoryWrite.ConnectInput(andOfMemoryWrite.Output);

            //8. create inputs for jump mux
            Wire on = new Wire();

            on.Value = 1;
            Wire off = new Wire();

            off.Value = 0;

            m_gJumpMux = new BitwiseMultiwayMux(1, 3);  // so i'm gonna use it as jump box in lesson
            jumpOr1    = new OrGate();
            jumpOr1.ConnectInput1(m_gALU.Zero);
            jumpOr1.ConnectInput2(m_gALU.Negative);
            jumpNot1 = new NotGate();
            jumpNot1.ConnectInput(jumpOr1.Output);
            jumpNot2 = new NotGate();
            jumpNot2.ConnectInput(m_gALU.Negative);
            jumpNot3 = new NotGate();
            jumpNot3.ConnectInput(m_gALU.Zero);
            jumpOr2 = new OrGate();
            jumpOr2.ConnectInput1(m_gALU.Zero);
            jumpOr2.ConnectInput2(m_gALU.Negative);

            Wire input1 = off; // we did somthing like this in practical session
            Wire input2 = jumpNot1.Output;
            Wire input3 = m_gALU.Zero;
            Wire input4 = jumpNot2.Output;
            Wire input5 = m_gALU.Negative;
            Wire input6 = jumpNot3.Output;
            Wire input7 = jumpOr2.Output;
            Wire input8 = on;


            //9. connect jump mux (this is the most complicated part
            m_gJumpMux.Inputs[0][0].ConnectInput(input1);
            m_gJumpMux.Inputs[1][0].ConnectInput(input2);
            m_gJumpMux.Inputs[2][0].ConnectInput(input3);
            m_gJumpMux.Inputs[3][0].ConnectInput(input4);
            m_gJumpMux.Inputs[4][0].ConnectInput(input5);
            m_gJumpMux.Inputs[5][0].ConnectInput(input6);
            m_gJumpMux.Inputs[6][0].ConnectInput(input7);
            m_gJumpMux.Inputs[7][0].ConnectInput(input8);

            m_gJumpMux.Control[0].ConnectInput(Instruction[J3]);
            m_gJumpMux.Control[1].ConnectInput(Instruction[J2]);
            m_gJumpMux.Control[2].ConnectInput(Instruction[J1]);

            //10. connect PC load control
            andOfpc = new AndGate();
            andOfpc.ConnectInput1(Instruction[Type]);
            andOfpc.ConnectInput2(m_gJumpMux.Output[0]);


            m_rPC.ConnectLoad(andOfpc.Output);
        }