Ejemplo n.º 1
0
        /// <summary>
        /// Get the opcode.
        /// </summary>
        /// <param name="inputBits">instruction bits</param>
        /// <returns>Operation</returns>
        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:
                throw new System.Exception("Invalid Opcode.");
            }
        }
 private void DecodeFirstOperand(int inputBits)
 {
     operandOneValue = inputBits & BitUtilities.CreateBitMask(operandOneStartBit, operandOneEndBit);
     if (operandOneValue < 0 || operandOneValue > 15)
     {
         operandTwoMeaning = $"OP1: Ya fucke* up";
     }
     else
     {
         operandOneMeaning = $"r{operandOneValue}";
     }
 }
        private void DecodeSecondOperand(int inputBits)
        {
            operandTwoValue = inputBits & BitUtilities.CreateBitMask(operandTwoStartBit, operandTwoEndBit);

            // Immediate or Register?
            if (immediateSwitchValue == 0)   // if register
            {
                if (operandTwoValue < 0 || operandTwoValue > 15)
                {
                    operandTwoMeaning = $"OP2: Ya fucke* up";
                }
                operandTwoMeaning = $"r{operandTwoValue}";
            }
            else      // else is an immediate
            {
                operandTwoMeaning = $"#{operandTwoValue}";
            }
        }
Ejemplo n.º 4
0
 private void DecodeSecondOperand(int inputBits)
 {
     // Immediate or Register?
     if (immediateSwitchValue == (int)ImmediateSwitchEnum.immediate)  // This is an immediate value.
     {
         operandTwoValue   = inputBits & BitUtilities.CreateBitMask(immediateOperandStartBit, operandTwoEndBit);
         operandTwoMeaning = $"#{operandTwoValue}";
     }
     else
     {
         operandTwoValue = inputBits & BitUtilities.CreateBitMask(operandTwoStartBit, operandTwoEndBit);
         if (operandTwoValue < 0 || operandTwoValue > 15)
         {
             operandTwoMeaning = $"OP2: Ya fucke* up";
         }
         operandTwoMeaning = $"r{operandTwoValue}";
     }
 }
 /// <summary>
 /// Decode value of the immediateSwitch
 /// </summary>
 /// <param name="inputBits">our instruction</param>
 private void DecodeImmediateSwitch(int inputBits)
 {
     immediateSwitchValue = inputBits & BitUtilities.CreateBitMask(immediateSwitchStartBit, immediateSwitchEndBit);
 }