static void Main(string[] args) { Machine16 machine = new Machine16(false, true); machine.Code.LoadFromFile(@"Fibonacci.hack"); machine.Data[0] = 12; machine.Data[1] = 0; DateTime dtStart = DateTime.Now; machine.Reset(); for (int i = 0; i < 12000; i++) { //machine.CPU.PrintState(); Console.WriteLine(); Clock.ClockDown(); Clock.ClockUp(); } for (int i = 100; i < 120; i++) { Console.WriteLine(machine.Data[i] + ","); } Console.ReadLine(); //Console.WriteLine("Done " + (DateTime.Now - dtStart).TotalSeconds); //Console.ReadLine(); }
static void Main(string[] args) { const string FilePath = @"Assembly examples\Product.hack"; Machine16 machine = new Machine16(bUseKeyboard: false, bUseScreen: true); machine.Code.LoadFromFile(FilePath); Func <bool> whileCondition = GetRunningCondition(FilePath, machine); machine.Data[0] = 9; machine.Data[1] = 7; for (int i = 100; i <= 200; i++) { machine.Data[i] = 5 + i; } DateTime dtStart = DateTime.Now; machine.Reset(); int consecutiveZeros = 0; while (whileCondition() && !ReadConsecutiveZeros(machine.Code, machine.CPU.PC, ref consecutiveZeros)) { machine.CPU.PrintState(); Console.WriteLine(); Clock.ClockDown(); Clock.ClockUp(); } Console.WriteLine(machine.Data[2]); Console.WriteLine("Done " + (DateTime.Now - dtStart).TotalSeconds); Console.ReadLine(); }
private static Func <bool> GetRunningCondition(string FilePath, Machine16 machine) { Func <bool> whileCondition; int lastInstruction = FindLastInstruction(machine.Code); bool isLastInstructionJump = IsLastInstructionJump(machine.Code, lastInstruction); if (isLastInstructionJump) { whileCondition = () => !(machine.CPU.PC == lastInstruction && machine.CPU.AReg == lastInstruction - 1); } else { whileCondition = () => machine.CPU.PC <= lastInstruction; } return(whileCondition); }
static void Main(string[] args) { Machine16 machine = new Machine16(false, true); machine.Code.LoadFromFile(@"D:\Teaching\ECS\Excersises\Ex2\Assembly examples\ScreenExample.hack"); machine.Data[0] = 100; machine.Data[1] = 15; DateTime dtStart = DateTime.Now; machine.Reset(); for (int i = 0; i < 1000; i++) { machine.CPU.PrintState(); Console.WriteLine(); Clock.ClockDown(); Clock.ClockUp(); } Console.WriteLine("Done " + (DateTime.Now - dtStart).TotalSeconds); Console.ReadLine(); }
static void Main(string[] args) { Machine16 machine = new Machine16(false, true); machine.Code.LoadFromFile(@"C:\Users\lueea\Desktop\Assembly examples\Sum100To200.hack"); machine.Data[0] = 100; machine.Data[1] = 15; DateTime dtStart = DateTime.Now; machine.Reset(); for (int i = 0; i < 200; i++) { machine.CPU.PrintState(); Console.WriteLine(); Clock.ClockDown(); Clock.ClockUp(); } Console.WriteLine("Done " + (DateTime.Now - dtStart).TotalSeconds); Console.ReadLine(); }