Beispiel #1
0
        public bool set_controls(ref Register_File rf, ref Multiplexer alu_src, ref Memory mem,
                                 ref ALU alu, ref Multiplexer memtoreg, ref Branch_AND_Gate bag,
                                 ref Multiplexer regdest, ref Multiplexer ec,
                                 ref Multiplexer writedt_dest, ref Multiplexer jalr_or_pc,
                                 ref Multiplexer jump_or_pc)
        {
            switch (Opcode)
            {
            case "0000":
                regdest.Destination  = true;
                alu_src.Destination  = false;
                memtoreg.Destination = true;
                rf.RegWrite          = true;
                mem.MemRead          = false;
                mem.MemWrite         = false;
                bag.Control_Unit     = false;
                //ec.Destination = true; don't care
                writedt_dest.Destination = true;
                jalr_or_pc.Destination   = false;
                jump_or_pc.Destination   = false;
                alu.Alu_Ctrl             = "000";
                break;    // extension control = don't care

            case "0001":
                regdest.Destination  = true;
                alu_src.Destination  = false;
                memtoreg.Destination = true;
                rf.RegWrite          = true;
                mem.MemRead          = false;
                mem.MemWrite         = false;
                bag.Control_Unit     = false;
                //ec.Destination = false; don't care
                writedt_dest.Destination = true;
                jalr_or_pc.Destination   = false;
                jump_or_pc.Destination   = false;
                alu.Alu_Ctrl             = "001";
                break;

            case "0010":
                regdest.Destination  = true;
                alu_src.Destination  = false;
                memtoreg.Destination = true;
                rf.RegWrite          = true;
                mem.MemRead          = false;
                mem.MemWrite         = false;
                bag.Control_Unit     = false;
                //ec.Destionation
                writedt_dest.Destination = true;
                jalr_or_pc.Destination   = false;
                jump_or_pc.Destination   = false;
                alu.Alu_Ctrl             = "010";
                break;

            case "0011":
                regdest.Destination  = true;
                alu_src.Destination  = false;
                memtoreg.Destination = true;
                rf.RegWrite          = true;
                mem.MemRead          = false;
                mem.MemWrite         = false;
                bag.Control_Unit     = false;
                //ec.Destination
                writedt_dest.Destination = true;
                jalr_or_pc.Destination   = false;
                jump_or_pc.Destination   = false;
                alu.Alu_Ctrl             = "011";
                break;

            case "0100":
                regdest.Destination  = true;
                alu_src.Destination  = false;
                memtoreg.Destination = true;
                rf.RegWrite          = true;
                mem.MemRead          = false;
                mem.MemWrite         = false;
                bag.Control_Unit     = false;
                //ec.Destination
                writedt_dest.Destination = true;
                jalr_or_pc.Destination   = false;
                jump_or_pc.Destination   = false;
                alu.Alu_Ctrl             = "100";
                break;

            case "0101":
                regdest.Destination      = false;
                alu_src.Destination      = true;
                memtoreg.Destination     = true;
                rf.RegWrite              = true;
                mem.MemRead              = false;
                mem.MemWrite             = false;
                bag.Control_Unit         = false;
                ec.Destination           = false;
                writedt_dest.Destination = true;
                jalr_or_pc.Destination   = false;
                jump_or_pc.Destination   = false;
                alu.Alu_Ctrl             = "000";
                break;

            case "0110":
                regdest.Destination      = false;
                alu_src.Destination      = true;
                memtoreg.Destination     = true;
                rf.RegWrite              = true;
                mem.MemRead              = false;
                mem.MemWrite             = false;
                bag.Control_Unit         = false;
                ec.Destination           = false;
                writedt_dest.Destination = true;
                jalr_or_pc.Destination   = false;
                jump_or_pc.Destination   = false;
                alu.Alu_Ctrl             = "010";
                break;

            case "0111":
                regdest.Destination      = false;
                alu_src.Destination      = true;
                memtoreg.Destination     = true;
                rf.RegWrite              = true;
                mem.MemRead              = false;
                mem.MemWrite             = false;
                bag.Control_Unit         = false;
                ec.Destination           = true;
                writedt_dest.Destination = true;
                jalr_or_pc.Destination   = false;
                jump_or_pc.Destination   = false;
                alu.Alu_Ctrl             = "011";
                break;

            case "1000":
                regdest.Destination      = false;
                alu_src.Destination      = true;
                memtoreg.Destination     = true;
                rf.RegWrite              = true;
                mem.MemRead              = false;
                mem.MemWrite             = false;
                bag.Control_Unit         = false;
                ec.Destination           = true;
                writedt_dest.Destination = true;
                jalr_or_pc.Destination   = false;
                jump_or_pc.Destination   = false;
                alu.Alu_Ctrl             = "111";
                break;

            case "1001":
                regdest.Destination      = false;
                alu_src.Destination      = true;
                memtoreg.Destination     = false;
                rf.RegWrite              = true;
                mem.MemRead              = true;
                mem.MemWrite             = false;
                bag.Control_Unit         = false;
                ec.Destination           = false;
                writedt_dest.Destination = true;
                jalr_or_pc.Destination   = false;
                jump_or_pc.Destination   = false;
                alu.Alu_Ctrl             = "000";
                break;

            case "1010":
                //regdest.Destination = false; don't care
                alu_src.Destination = true;
                //memtoreg.Destination = false; don't care
                rf.RegWrite              = false;
                mem.MemRead              = false;
                mem.MemWrite             = true;
                bag.Control_Unit         = false;
                ec.Destination           = false;
                writedt_dest.Destination = true;
                jalr_or_pc.Destination   = false;
                jump_or_pc.Destination   = false;
                alu.Alu_Ctrl             = "000";
                break;

            case "1011":
                //regdest.Destination = false; don't care
                alu_src.Destination = false;
                //memtoreg.Destination = false; don't care
                rf.RegWrite              = false;
                mem.MemRead              = false;
                mem.MemWrite             = false;
                bag.Control_Unit         = true;
                ec.Destination           = false;
                writedt_dest.Destination = true;
                jalr_or_pc.Destination   = false;
                jump_or_pc.Destination   = false;
                alu.Alu_Ctrl             = "001";
                break;

            case "1100":
                regdest.Destination = false;
                //alu_src.Destination = true;
                memtoreg.Destination     = false;
                rf.RegWrite              = true;
                mem.MemRead              = false;
                mem.MemWrite             = false;
                bag.Control_Unit         = false;
                ec.Destination           = false;
                writedt_dest.Destination = false;
                jalr_or_pc.Destination   = true;
                jump_or_pc.Destination   = false;
                alu.Alu_Ctrl             = "000";
                break;

            case "1101":
                //regdest.Destination = false; don't care
                alu_src.Destination      = true;
                memtoreg.Destination     = false;
                rf.RegWrite              = false;
                mem.MemRead              = false;
                mem.MemWrite             = false;
                bag.Control_Unit         = false;
                ec.Destination           = false;
                writedt_dest.Destination = true;
                jalr_or_pc.Destination   = false;
                jump_or_pc.Destination   = true;
                alu.Alu_Ctrl             = "000";
                break;

            case "1110":
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        public void calculate(ref Multiplexer alu_scr, ref Memory mem, ref Multiplexer memtoreg, ref Branch_AND_Gate bag)
        {
            switch (Alu_Ctrl)
            {
            case "000":
                int operand1 = Convert.ToInt32(ReadData1, 2);
                int operand2 = Convert.ToInt32(alu_scr.Result(), 2);
                int result   = operand1 + operand2;
                mem.Address  = result;
                memtoreg.One = Convert.ToString(result, 2);
                break;

            case "001":
                operand1 = Convert.ToInt32(ReadData1, 2);
                operand2 = Convert.ToInt32(alu_scr.Result(), 2);
                result   = operand1 - operand2;
                if (result == 0)
                {
                    bag.ALU_Zero = true;
                }
                mem.Address  = result;
                memtoreg.One = Convert.ToString(result, 2);
                break;

            case "010":
                operand1 = Convert.ToInt32(ReadData1, 2);
                operand2 = Convert.ToInt32(alu_scr.Result(), 2);
                if (operand1 < operand2)
                {
                    result = 1;
                }
                else
                {
                    result = 0;
                }
                mem.Address  = result;
                memtoreg.One = Convert.ToString(result, 2);
                break;

            case "011":
                operand1     = Convert.ToInt32(ReadData1, 2);
                operand2     = Convert.ToInt32(alu_scr.Result(), 2);
                result       = operand2 | operand2;
                mem.Address  = result;
                memtoreg.One = Convert.ToString(result, 2);
                break;

            case "100":
                operand1     = Convert.ToInt32(ReadData1, 2);
                operand2     = Convert.ToInt32(alu_scr.Result(), 2);
                result       = operand1 ^ operand2;
                mem.Address  = result;
                memtoreg.One = Convert.ToString(result, 2);
                break;

            case "111":
                operand2     = Convert.ToInt32(alu_scr.Result(), 2);
                result       = operand2 << 16;
                mem.Address  = result;
                memtoreg.One = Convert.ToString(result, 2);
                break;
            }
        }