public static bool ProgramHalts(InstructionProcessor processor) { var instructionExecutedTrackingArray = new bool[processor.Instructions.Length]; instructionExecutedTrackingArray[processor.CurrentInstructionPointer] = true; while (!processor.Halted) { processor.Step(); if (processor.Halted) { continue; } if (instructionExecutedTrackingArray[processor.CurrentInstructionPointer]) { return(false); } instructionExecutedTrackingArray[processor.CurrentInstructionPointer] = true; } return(true); }
public int GetAccumulatorAtFirstLoop() { var instructionExecutedTrackingArray = new bool[_instructions.Length]; var instructionProcessor = new InstructionProcessor(_instructions); instructionExecutedTrackingArray[instructionProcessor.CurrentInstructionPointer] = true; while (!instructionProcessor.Halted) { instructionProcessor.Step(); if (instructionExecutedTrackingArray[instructionProcessor.CurrentInstructionPointer]) { return(instructionProcessor.Accumulator); } instructionExecutedTrackingArray[instructionProcessor.CurrentInstructionPointer] = true; } return(instructionProcessor.Accumulator); }