public void TestHappyCommand() { Processor p = new Processor(); AssemblerInstruction cmd = Processor.ParseInstruction("MOV EAX, 10"); p.ExecuteCommand(cmd); Assert.AreEqual((UInt32)10, p.GetRegister().GetRegister(Register.REGISTERS.A)); cmd = Processor.ParseInstruction("MOV CX, 56"); p.ExecuteCommand(cmd); Assert.AreEqual((UInt32)56, p.GetRegister().GetRegister(Register.REGISTERS.C, Register.LEVEL.LOW)); cmd = Processor.ParseInstruction("MOV BL, 250"); p.ExecuteCommand(cmd); Assert.AreEqual((UInt32)250, p.GetRegister().GetRegister(Register.REGISTERS.B, Register.LEVEL.LOW, Register.LEVEL.LOW)); cmd = Processor.ParseInstruction("MOV DH, 11"); p.ExecuteCommand(cmd); Assert.AreEqual((UInt32)11, p.GetRegister().GetRegister(Register.REGISTERS.D, Register.LEVEL.LOW, Register.LEVEL.HIGH)); cmd = Processor.ParseInstruction("MOV DL, DH"); p.ExecuteCommand(cmd); Assert.AreEqual((UInt32)11, p.GetRegister().GetRegister(Register.REGISTERS.D, Register.LEVEL.LOW, Register.LEVEL.LOW)); cmd = Processor.ParseInstruction("MOV EAX, DH"); p.ExecuteCommand(cmd); Assert.AreEqual((UInt32)11, p.GetRegister().GetRegister(Register.REGISTERS.A)); cmd = Processor.ParseInstruction(" MOV ECX, 111 "); //spaces p.ExecuteCommand(cmd); Assert.AreEqual((UInt32)111, p.GetRegister().GetRegister(Register.REGISTERS.C)); }
private void processCommand(string text) { AssemblerInstruction instruction = Processor.ParseInstruction(text); mProc.ExecuteCommand(instruction); UpdateRegisters(); }
private void RunProgram(bool step = false) { short instruction = -1; while (instruction != 0 && Running) { if (abort) { Running = false; break; } instruction = Context.Memory.Read <short>(ProgramCounter.Address); if (instruction == 0 || instruction == -1) { Running = false; break; } byte opcode = (byte)(instruction & 0xFF); byte paramsTypes = (byte)((instruction & 0x3F00) >> 8); byte paramsFlagsBinary = (byte)((instruction & 0xC000) >> 14); bool[] paramsFlags = new bool[] { (paramsFlagsBinary & 0x1) != 0, (paramsFlagsBinary & 0x2) != 0 }; uint mem = ProgramCounter.Address + 2; AssemblerInstruction asm = InstructionSet[opcode]; AssemblerParameterValue[] param = new AssemblerParameterValue[asm.ParametersCount]; for (int i = 0; i < asm.ParametersCount; i++) { byte pt = (byte)((paramsTypes & (0x03 << i * 2)) >> i * 2); if (asm.Parameters[i] == AssemblerParameters.Register) { param[i] = programMemoryReader.ReadRegister(ref mem, pt, i < 2 ? paramsFlags[i] : false); } else if ((asm.Parameters[i] & AssemblerParameters.Value) != 0) { param[i] = programMemoryReader.ReadValue(ref mem, pt, i < 2 ? paramsFlags[i] : false); } else if (asm.Parameters[i] == AssemblerParameters.Pointer) { param[i] = programMemoryReader.ReadPointer(ref mem, pt, i < 2 ? paramsFlags[i] : false); } } ProgramCounter.Set(mem); try { asm.Eval(Context, param); } catch (InterruptSignal interrupt) { } if (step) { break; } } }
public void ExecuteCommand(AssemblerInstruction instruction) { instruction.ExecuteCommand(this); }