Question: Need help with this CS problem: 1. The run_bit would be typically part of a PS (Processor Status)/Flag register. Modify the code below to implement
Need help with this CS problem: 1. The run_bit would be typically part of a PS (Processor Status)/Flag register. Modify the code below to implement more of the features of a PS by adding another bit for debugging. When this bit is set, the processor that we are simulating will be in debug mode. When in debug mode, our simulator should output the contents of the AC after every instruction. 2. Implement the following instructions: CLR <-- set the value in the AC to 0 ADDI x <-- add the value x to the AC ADDM y <-- add the value in memory location y to AC HALT <-- instruction which halts the processor 2.a. All instructions (opcodes and operands) are simply numbers (integers) in memory. For this step, simply define unique integer constants for each of the above opcodes. 2.b. Next, implement the find_data and execute methods. (Modifications to interpret may be necessary as well.) 3. Enter and run code (typically in main) such as the following for this machine: int m2[] = { 2, -5, 15, CLR, //"program" starts here ADDI, 12, ADDI, 7, ADDM, 0, ADDM, 1, CLR, HALT }; interpret( m2, 3 ); //start at CLR As part of this assignment, answer the following question. What is the value of the PC and AC after each of the above instructions executes? 4. Test your "processor/simulator" by giving it sample "programs" (at least 2). Email your code and test output to me with the (required, please) subject: Interpreter1. */ //---------------------------------------------------------------------- /* file : Interpreter.java date : author: description: */ //---------------------------------------------------------------------- public class Interpreter { static int PC; //program counter holds address of next instr static int AC; //the accumulator - a register for doing arithmetic static boolean run_bit = true; //a bit that can be turned off to halt the machine static int instr; //a holding register for the current instruction static int instr_type; //the instruction type (opcode) static int data_loc; //the address of the data, or -1 if none static int data; //holds the current operand //------------------------------------------------------------------ //This procedure interprets programs for a simple machine. The machine //has a register AC (accumulator), used for arithmetic. The interpreter //keeps running until the run bit is turned off by the HALT instruction. //The state of a process running on this machine consists of the memory, //the program counter, the run bit, and the AC. The input parameters //consist of the memory image and the starting address. public static void interpret ( int memory[], int starting_address ) { PC = starting_address; run_bit = true; while (run_bit) { instr = memory[PC]; //fetch next instruction into instr PC = PC + 1; //increment program counter instr_type = get_instr_type( instr ); //determine instruction type data_loc = find_data( instr, instr_type, memory ); //locate data (-1 if none) if (data_loc >= 0) { //if data_loc is -1, there is no operand data = memory[data_loc]; //fetch the data } execute( instr_type, data ); //execute instruction } } //------------------------------------------------------------------ //since our instruction set is so simple, we'll let the opcode and // instruction type be the same. private static int get_instr_type ( int opcode ) { return opcode; } //------------------------------------------------------------------ private static int find_data ( int opcode, int type, int memory[] ) { ... } //------------------------------------------------------------------ private static void execute ( int type, int data ) { ... } } // Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
