Exemplo n.º 1
0
        private ProcessContextBlock Run(IEnumerable <Instruction> program, Cpu cpu)
        {
            IdleProcess.Initialise(cpu);

            var prog1 = cpu.Load();

            var codeSize = cpu.Compile(prog1, program);

            Console.WriteLine("Code Size: {0} bytes", codeSize);

            cpu.Run(prog1);

            var timeout = 1000;

            while (prog1.IsRunning)
            {
                cpu.Tick();
                timeout--;
                if (timeout == 0)
                {
                    throw new Exception("Timed out while running program");
                }
            }

            return(prog1);
        }
Exemplo n.º 2
0
        public void ProgramSignals()
        {
            var cpu = new Cpu(2048, 256);

            IdleProcess.Initialise(cpu, IdleProcess.Instructions);

            var prog1 = cpu.Load();
            var prog2 = cpu.Load();

            cpu.Compile(prog1, TestPrograms.P1);
            cpu.Compile(prog2, TestPrograms.P2);

            cpu.Run(prog1);
            cpu.Run(prog2);

            while (prog1.IsRunning || prog2.IsRunning)
            {
                cpu.Tick();
            }

            Assert.That(prog1.ExitCode, Is.EqualTo(1));
            Assert.That(prog2.ExitCode, Is.EqualTo(1));
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            var cpu = new Cpu(CpuConfigLibrary.Cpu32Bit.Build());

            const string code = @"
in

_start  call_eq_v   0       done
        sub_v       1
	    call        start

_done   out
        halt
";

            cpu.Compile(code);
            cpu.Execute();
        }
Exemplo n.º 4
0
        public void RunCpuWithProgram()
        {
            var cpu = new Cpu(2048, 256);

            IdleProcess.Initialise(cpu, IdleProcess.Instructions);

            var prog1 = cpu.Load();

            cpu.Compile(prog1, TestPrograms.ReallySimpleProgram);
            cpu.Run(prog1);

            while (prog1.IsRunning)
            {
                cpu.Tick();
            }

            Assert.That(prog1.ExitCode, Is.EqualTo(1));
        }