Exemplo n.º 1
0
        public static BootCodeInstruction ParseBootCodeInstruction(string instructionLine)
        {
            var match = Regex.Match(instructionLine, @"^(\w+) ((\+|-)\d+)$");

            if (!match.Success)
            {
                throw new Exception($"Unrecognized instruction line: {instructionLine}");
            }
            var instruction = match.Groups[1].Value.Trim();
            var value       = int.Parse(match.Groups[2].Value.Trim());
            var result      = new BootCodeInstruction(instruction, value);

            return(result);
        }
Exemplo n.º 2
0
        public static IList <BootCode> GetPossiblyFixedBootCodes(BootCode bootCode)
        {
            var result = new List <BootCode>();

            for (int i = 0; i < bootCode.Instructions.Count; i++)
            {
                var currentInstruction = bootCode.Instructions[i];
                if ("jmp".Equals(currentInstruction.Instruction) ||
                    "nop".Equals(currentInstruction.Instruction))
                {
                    var instructionsCopy = bootCode.Instructions.ToList();
                    var newInstruction   = "jmp".Equals(currentInstruction.Instruction) ? "nop" : "jmp";
                    instructionsCopy[i] = new BootCodeInstruction(newInstruction, currentInstruction.Value);
                    var newBootCode = new BootCode(instructionsCopy);
                    result.Add(newBootCode);
                }
            }
            return(result);
        }