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); } }
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."); } }
/// <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."); } }