import java.io.FileReader;import java.io.FileWriter;import java.io.PrintWriter;import java.io.FileNotFoundException;import java.io.IOException;public class Program // Test driver for CPU simulator. // Illustrates readers/writers conflicts{	static FileReader inp;	static PrintWriter outp;		// Give symbolic names to two variables.	static final int control = 0;	static final int buffer = 1;		// Define label names for the writer.	static final int topW = 10;	static final int waitW = 20;	static final int startW = 30;		// Define label names for the reader.	static final int topR = 10;	static final int waitR = 20;	static final int startR = 30;		public static void main(String argv[])	{	boolean tracing = true;		Simulator M = new Simulator();		try { inp = new FileReader("prog.in");}		catch(FileNotFoundException e)		{	System.out.println("No input file--halting.");			System.exit(1);		}		try 		{ 	outp = new PrintWriter(new FileWriter("prog.out"));						CPUProcess writer = new CPUProcess(0, inp, outp, tracing);					// Use constants or literals to name memory locations				writer.declare(control);	// Memory 0 is the controller			writer.declare(buffer);	// Memory 1 is the buffer			writer.label(topW);			writer.input();			writer.JMP(startW);			writer.label(waitW);			writer.toss();			// Instr 4			writer.label(startW);			writer.pushv(control);			writer.JGZ(waitW);		// busywait until empty (== 0)			writer.toss();			writer.pop(buffer);		// load the buffer			writer.pushi(1);			writer.pop(control);	// set the controller = full			writer.JMP(topW);		// repeat			writer.halt();			// not executed			M.insertProcess(writer);						System.out.print("Writer " + writer);						CPUProcess reader1 = new CPUProcess(1, inp, outp, tracing);						reader1.declare(control);			reader1.declare(buffer);			reader1.label(topR);			reader1.JMP(startR);			reader1.label(waitR);			reader1.toss(); 		// Instr 3			reader1.label(startR);			reader1.pushv(control);			reader1.JEZ(waitR); 	// busywait until full (== 1)			reader1.toss();			reader1.pushv(buffer);	// empty the buffer			reader1.output();			reader1.toss();			reader1.pushi(0);			reader1.pop(control);	// set the controller = empty			reader1.JMP(topR);		// repeat			reader1.halt();			// not executed			M.insertProcess(reader1);			System.out.print("Reader1 " + reader1);						CPUProcess reader2 = (CPUProcess)reader1.clone();			reader2.setSerialNumber(2);			M.insertProcess(reader2);						System.out.print("Reader2 " + reader2);			M.step(1000);					System.out.println( M );			outp.close();		}		catch(IOException e)		{	System.out.println("No output file. Can't run.");		}	}}	// exercises  	// Add a control level that will make the use of this interactive.  Instead of the code in main	// that you see here, provide a menu of options like 	//   step n	//   dump	//   quit	// The environment accepts and exeuctes commands until the user chooses quit. 	//			You may want to adapt the scanner and parser from spreadsheet to this.	//			You will want to write a grammar for your command language. 