public void Solve() { AsmInterpretor interpretor = new AsmInterpretor(); interpretor.Load(this.instructions); interpretor.InstructionMoved += Interpretor_InstructionMoved; var instructions = interpretor.Instructions; var instructionCount = interpretor.InstructionCount; for (int i = 0; i < instructionCount; i++) { if (instructions[i].OpCode != Opcode.Jmp && instructions[i].OpCode != Opcode.Nop) { continue; } var originalInstruction = instructions[i]; instructions[i] = originalInstruction with { OpCode = instructions[i].OpCode == Opcode.Jmp ? Opcode.Nop : Opcode.Jmp }; visitedInstructions = new BitArray(2048); if (interpretor.Execute()) { Log.Information("Loop fix detected. Accumulator is {Accumulator}", interpretor.AccumulatorValue); break; } instructions[i] = originalInstruction; } }
public void Solve() { AsmInterpretor interpretor = new AsmInterpretor(); interpretor.Load(this.instructions); interpretor.InstructionMoved += Interpretor_InstructionMoved; interpretor.Execute(0); }