hELP WITH A PROCESSOR SIMULATION
Hello All,
Im trying to create a simple processor simulation but Im having the toughest time storing my file and then creating the Algorithms needed for my PC, AC, and MAR registers.
Heres the instructions for the algorithm:
00 (DATA) Not an instruction. Memory location holds some data value.
01 LOAD Load memory into AC register
02 ADD Add memory into AC register
03 SUB Subtract memory from AC register
04 JUMP Set PC Register to memory
05 MOV Copy AC into Memory
15 HALT Stop all execution. Your program ends here. Output the current state of memory and all register values.
*Numbers on the side is the opcode
• The maximum value for an opcode is 15. The maximum value for a memory address or a memory value is 9999.
Constraints:
• The only available memory is what is given in the initial text file.
• All lines are separated by newline characters (\n). All characters in the textfile are encoded using standard ASCII.
• There will not be any invalid instructions in memory.
• Upon starting the PC register will always point to valid memory.
• The PC register will be incremented by one after each instruction, except when you encounter a JUMP. Just set the PC register to the proper value when you encounter a JUMP.
• No JUMP instruction will ever take you to non-executable memory.
• You should interpret all integer values in the text file as base-10 (decimal) numbers.
• When you reach a HALT instruction, you are done executing.
• A MOV instruction leaves the AC intact.
• The MAR changes in accordance with the memory address last accessed by a LOAD, ADD, SUB, JUMP, or MOV instruction.
Code I have thus far:
import java.io.*;
class Simulator
{
public static void main(String args[])
{
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("memory.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
SOMEONE PLZ HELP ME!!!