Esempio n. 1
0
        private static string DecodeInput(int input)
        {
            InstructionType ourInstruction = null;

            // I Check instruction type (Bits 14-15)
            // I.A SHOW bits 14-15
            int bitmask     = BitUtilities.CreateBitMask(14, 15); //1100 0000 0000
            int maskedinput = input & bitmask;

            switch (maskedinput)
            {
            case 0x0000:        //00 - data transfer
                Console.Write("00");
                ourInstruction = new DataTransferType();
                break;

            case 0x4000:        //01 - arithmetic/logical
                Console.Write("01");
                ourInstruction = new ArithmeticType();
                break;

            case 0x8000:        //10 - flow control
                Console.Write("10");
                ourInstruction = new FlowControlType();
                break;

            default:
                Console.Write("Instruction Type broke");
                break;
            }

            try {
                // Decode input
                string output = ourInstruction.DecodeInstruction(input);
                return(output);
            }
            catch (Exception e) {
                return($"{e.Message} You dun f****d up.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Decode the input from the user.
        /// </summary>
        /// <param name="input">from user</param>
        /// <returns>a string representing a human-readable text translation of the machine code read and translated by the ISA architecture.</returns>
        private static string DecodeInput(int input)
        {
            InstructionType ourInstruction = null;

            // I Check instruction type (Bits 14-15)
            // I.A SHOW bits 14-15
            int bitmask     = BitUtilities.CreateBitMask(14, 15); //1100 0000 0000
            int maskedinput = input & bitmask;

            switch (maskedinput)
            {
            case 0x0000:        //00 - data transfer
                ourInstruction = new DataTransferType();
                break;

            case 0x4000:        //01 - arithmetic/logical
                ourInstruction = new ArithmeticType();
                break;

            case 0x8000:        //10 - flow control
                ourInstruction = new FlowControlType();
                break;

            default:
                return("Invalid Instruction Type!");
            }

            try {
                // Decode input
                string output = ourInstruction.DecodeInstruction(input);
                return(output);
            }
            // Oh no! Something went a wrong!
            catch (Exception e) {
                return($"{e.Message} You dun messed up.");
            }
        }