package lab04;

public class TryCPU {

	public static void main(String[] args) {
		Program prog = new Program();
		prog.add(new Instruction("LOD","DIR",0));
		prog.add(new Instruction("DIV","IMM",2));
		prog.add(new Instruction("MUL","IMM",2));
		prog.add(new Instruction("SUB","DIR",0));
		prog.add(new Instruction("MUL","IMM",-1));
		prog.add(new Instruction("STO","DIR",1));
		prog.add(new Instruction("HLT","IMM",0));
		
		if (args.length<1) {
			System.out.println("Run as TryCPU [-trace] N");
			System.out.println("   where -trace is optional, and N is any number.");
			return;
		}
		
		int nextArg=0;
		if (args[nextArg].equals("-trace")) { 
			Trace.startTrace();
			nextArg++;
		}
		Memory mem=new Memory(1024);
		CPU cpu = new CPU(mem);
		prog.load(cpu);
		
		cpu.setData(0, Integer.parseInt(args[nextArg])); // Put command line arg into mem[0]
		
		if (Trace.getTrace()) mem.dump("Memory Before execution");
		
		System.out.println("Running program on " + args[nextArg]);
		cpu.run();
		
		System.out.println(args[nextArg] + " is " + 
				(cpu.getData(1)==1?"odd":"even"));
	}

}
