Ejemplo n.º 1
0
        private static int[] FindJmpIndexes(SimpleProgram program)
        {
            var indexes = new List <int>();

            for (var i = 0; i < program.Count; i++)
            {
                if (program[i].Operator == SimpleProgram.Jmp)
                {
                    indexes.Add(i);
                }
            }
            return(indexes.ToArray());
        }
Ejemplo n.º 2
0
        private static SimpleProgram LoadProgram(string filename)
        {
            var lines = Utility.ReadLinesFromFile(filename);

            var program = new SimpleProgram();

            foreach (var line in lines)
            {
                var parts       = line.Split(" ");
                var instruction = new SimpleInstruction
                {
                    Operator = parts[0],
                    Operand  = Convert.ToInt32(parts[1])
                };

                program.Add(instruction);
            }

            return(program);
        }