Beispiel #1
0
 //------------------------------------------------------------------------------------------------------------
 private static EPML testProgramOne()
 {
     return(EPML.Make("Test Program One")
            .Description("EPML program that reads two integers and computes their sum.")
            .Add(+1007)   // Read A
            .Add(+1008)   // Read B
            .Add(+2007)   // Load A
            .Add(+3208)   // Add B
            .Add(+2109)   // Store C
            .Add(+1109)   // Write C
            .Add(+5000)   // Halt
            .Add(+0000)   // Variable A
            .Add(+0000)   // Variable B
            .Add(+0000)); // Result C
 }
Beispiel #2
0
 //------------------------------------------------------------------------------------------------------------
 private static EPML testProgramTwo()
 {
     return(EPML.Make("Test Program Two")
            .Description("EPML program that reads two numbers and displays the larger value")
            .Add(+1009)   // Read A
            .Add(+1010)   // Read B
            .Add(+2009)   // Load A
            .Add(+3310)   // Subtract B
            .Add(+4107)   // Branch negative to 07
            .Add(+1109)   // Write A
            .Add(+5000)   // Halt
            .Add(+1110)   // Write B
            .Add(+5000)   // Halt
            .Add(+0000)   // Variable A
            .Add(+0000)); // Variable B
 }
Beispiel #3
0
 //------------------------------------------------------------------------------------------------------------
 private static void runProgramFromFile(string filename, bool debugging = false)
 {
     // Assume that each line of the program file contains a location and instruction   eg. 01 +1009
     try
     {
         string[] lines   = File.ReadAllLines(filename);
         var      vm      = EPC.Make(debugging: debugging);
         var      program = EPML.Make().FillTo(vm.MemoryLimit).Load(lines);
         Console.Clear();
         vm.Run(program);
     }
     catch (IOException ex)
     {
         Console.WriteLine(ex.Message);
         Console.WriteLine(ex.StackTrace);
     }
 }
Beispiel #4
0
 //------------------------------------------------------------------------------------------------------------
 private static EPML testProgramThree()
 {
     return(EPML.Make("Test Program Three")
            .Description("EPML program that calculates several integers")
            .Add(+1098)
            .Add(+2098)
            .Add(+3397)
            .Add(+4211)
            .Add(+2098)
            .Add(+3098)
            .Add(+2195)
            .Add(+2095)
            .Add(+2196)
            .Add(+1196)
            .Add(+4000)
            .Add(+5000));
 }
Beispiel #5
0
        //------------------------------------------------------------------------------------------------------------
        private EPC loadProgram(EPML program)
        {
            Console.WriteLine($"*** Loading {program.Name} into memory ***");
            if (program.Description() != null && program.Description() != "")
            {
                Console.WriteLine($"*** {program.Description()} ***");
            }
            int max = _memory.Size();

            for (int i = 0; i < max; ++i)
            {
                var instruction = program.Instructions[i];
                _memory.Put(instruction, i);
            }
            Console.WriteLine("*** Program loading completed ***");
            Console.WriteLine("*** Program execution begins ***");

            execute();
            return(this);
        }
Beispiel #6
0
 //------------------------------------------------------------------------------------------------------------
 public EPC Run(EPML program)
 {
     _memory.Clear();
     return(loadProgram(program));
 }