/// <summary> /// Decode the instruction /// </summary> /// <param name="cmd"></param> /// <returns></returns> public static Instruction DecodeInstruction(Memory command) { Instruction i = new Instruction(); uint type = 0; // get type type = (uint)((command.ReadByte(3) & 0x0c) >> 2); //Console.WriteLine(Convert.ToString(command.ReadWord(0),2)); switch (type) { case 0: // Data Processing (00X) if ((0x012FFF10 & command.ReadWord(0)) == 0x012FFF10) { i = new Branch(); } else { i = new DataProcessing(); } break; case 1: // Load / Store (01X) if (command.TestFlag(0, 24) || !command.TestFlag(0, 21)) { i = new LoadStore(); } break; case 2: // Load / Store Multiple (100) if (!command.TestFlag(0, 25)) { //load store multiple i = new LoadStoreMultiple(); } // Branch Instruction (101) else { if (command.TestFlag(0, 27) && !command.TestFlag(0, 26) && command.TestFlag(0, 25)) { Logger.Instance.lastInstructionWasBranch = true; i = new Branch(); } } break; case 3: //11 //Coprocessor if (command.TestFlag(0, 26) && command.TestFlag(0, 25)) { //interupt } break; default: break; } i.ParseCommand(command); // get condition i.Cond = (uint)command.ReadByte(3) >> 4; // get type i.Type = (uint)((command.ReadByte(3) & 0x0c) >> 2); // i.initialBytes = (uint)command.ReadWord(0); // source i.Rn = (uint)((command.ReadWord(0) & 0x000F0000) >> 16); // destination i.Rd = (uint)((command.ReadWord(0) & 0x0000F000) >> 12); return i; }
/// <summary> /// Decode the instruction /// </summary> /// <param name="cmd"></param> /// <returns></returns> public static Instruction DecodeInstruction(Memory command) { Instruction i = new Instruction(); uint type = 0; // get type type = (uint)((command.ReadByte(3) & 0x0c) >> 2); //Console.WriteLine(Convert.ToString(command.ReadWord(0),2)); switch (type) { case 0: // Data Processing (00X) if ((0x012FFF10 & command.ReadWord(0)) == 0x012FFF10) { i = new Branch(); } else { i = new DataProcessing(); } break; case 1: // Load / Store (01X) if (command.TestFlag(0, 24) || !command.TestFlag(0, 21)) { i = new LoadStore(); } break; case 2: // Load / Store Multiple (100) if (!command.TestFlag(0, 25)) { //load store multiple i = new LoadStoreMultiple(); } // Branch Instruction (101) else { if (command.TestFlag(0, 27) && !command.TestFlag(0, 26) && command.TestFlag(0, 25)) { Logger.Instance.lastInstructionWasBranch = true; i = new Branch(); } } break; case 3: //11 //Coprocessor if (command.TestFlag(0, 26) && command.TestFlag(0, 25)) { //interupt } break; default: break; } i.ParseCommand(command); // get condition i.Cond = (uint)command.ReadByte(3) >> 4; // get type i.Type = (uint)((command.ReadByte(3) & 0x0c) >> 2); // i.initialBytes = (uint)command.ReadWord(0); // source i.Rn = (uint)((command.ReadWord(0) & 0x000F0000) >> 16); // destination i.Rd = (uint)((command.ReadWord(0) & 0x0000F000) >> 12); return(i); }