コード例 #1
0
        public Operation DecodeOpcode(int inputBits)
        {
            // Get mask for opcode + InstructionID
            opcode = inputBits & BitUtilities.CreateBitMask(opcodeStartBit, 15);

            switch (opcode)
            {
            case (int)opcodeIdentificationHexLiterals.hexADD:
                return(new ADDoperation());

            case (int)opcodeIdentificationHexLiterals.hexADC:
                return(new ADCoperation());

            case (int)opcodeIdentificationHexLiterals.hexSUB:
                return(new SUBoperation());

            case (int)opcodeIdentificationHexLiterals.hexMUL:
                return(new MULoperation());

            case (int)opcodeIdentificationHexLiterals.hexDIV:
                return(new DIVoperation());

            case (int)opcodeIdentificationHexLiterals.hexMOD:
                return(new MODoperation());

            case (int)opcodeIdentificationHexLiterals.hexAND:
                return(new ANDoperation());

            case (int)opcodeIdentificationHexLiterals.hexOR:
                return(new ORoperation());

            case (int)opcodeIdentificationHexLiterals.hexNOT:
                return(new NOToperation());

            case (int)opcodeIdentificationHexLiterals.hexNAND:
                return(new NANDoperation());

            case (int)opcodeIdentificationHexLiterals.hexJMP:
                return(new JMPoperation());

            case (int)opcodeIdentificationHexLiterals.hexJC:
                return(new JCoperation());

            case (int)opcodeIdentificationHexLiterals.hexCMP:
                return(new CMPoperation());

            case (int)opcodeIdentificationHexLiterals.hexNOP:
                return(new NOPoperation());

            case (int)opcodeIdentificationHexLiterals.hexLOAD:
                return(new LOADoperation());

            case (int)opcodeIdentificationHexLiterals.hexSTOR:
                return(new STORoperation());

            default:
                return(null);
            }
        }
コード例 #2
0
 /// <summary>
 /// Decode the first operand of this instruction by masking it and
 /// 1) Determining its value
 /// 2) Assigning it a textual meaning. (FIX THIS)
 /// </summary>
 /// <param name="inputBits">instruction bits</param>
 private void DecodeFirstOperand(int inputBits)
 {
     operandOneValue = BitUtilities.MaskInput(inputBits, operandOneStartBit, operandOneEndBit);
     if (operandOneValue < 0 || operandOneValue > 15) //used to check if valid register
     {                                                //used to check if valid register
         operandTwoMeaning = $"OP1: Ya messed* up";
     }
     else
     {
         operandOneMeaning = $"r{operandOneValue}";
     }
 }
コード例 #3
0
 /// <summary>
 /// used to get the value of the second operand and give it a meaning
 /// </summary>
 /// <param name="inputBits">instruction bits</param>
 private void DecodeSecondOperand(int inputBits)
 {
     // Immediate or Register?
     if (immediateSwitchValue == (int)ImmediateSwitchEnum.immediate)  // This is an immediate value.
     {
         operandTwoValue   = BitUtilities.MaskInput(inputBits, immediateOperandStartBit, operandTwoEndBit);
         operandTwoMeaning = $"#{operandTwoValue}";
     }
     else
     {
         operandTwoValue = BitUtilities.MaskInput(inputBits, operandTwoStartBit, operandTwoEndBit);
         if (operandTwoValue < 0 || operandTwoValue > 15)
         { //used to check if valid register
             operandTwoMeaning = $"OP2: Ya messed* up";
         }
         operandTwoMeaning = $"r{operandTwoValue}";
     }
 }
コード例 #4
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.");
            }
        }
コード例 #5
0
        /// <summary>
        /// used to get the addressing value and its meaning
        /// </summary>
        /// <param name="inputBits"></param>
        private void DecodeAddressingValue(int inputBits)
        {
            addressingModeValue = BitUtilities.MaskInput(inputBits, addressingModeStartBit, addressingModeEndBit);
            switch (addressingModeValue)
            {
            case 0:
                addressingModeMeaning = "immediate";
                break;

            case 1:
                addressingModeMeaning = "register indirect, indexed";
                break;

            case 2:
                addressingModeMeaning = "direct";
                break;

            case 3:
                addressingModeMeaning = "Error, invalid addressing mode.";
                break;
            }
        }
コード例 #6
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.");
            }
        }
コード例 #7
0
 /// <summary>
 /// Decode value of the immediateSwitch
 /// </summary>
 /// <param name="inputBits">our instruction</param>
 private void DecodeImmediateSwitch(int inputBits)
 {
     immediateSwitchValue = BitUtilities.MaskInput(inputBits, immediateSwitchStartBit, immediateSwitchEndBit);
 }