Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Status WAITING READY RUNNING HALTED Meaning Waiting to load a program into instruction memory A program has been loaded into instruction memory and is ready

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Status WAITING READY RUNNING HALTED Meaning Waiting to load a program into instruction memory A program has been loaded into instruction memory and is ready to run The machine is actively running a program The program halted the machine whether by a HALT instruction or reaching the end of the instructions The machine stopped because of an error in the ERRORED program Unknown status. Should never happen in normal UNKNOWN control flow The following image d emonstrates how the GritVM moves between states. Object Program is READY Run methed s celled RUNNING Evaluation WAITING lmemory is ERRORED HALTED The primary flow of the machine should be as follows When created, the GritVM sets the accumulator to 0, and it's status to WAITING .A program is loaded into the GritVM object by filename (by the load method) If the machine status is anything other than WAITING, return the current status . If the GritVM cannot read a file, the method throws an exception Each line of the file is read in and parsed into its proper instruction and argument . If the instruction is not recognized, change the machine status to ERRORED and return . If the line is blank or starts with a #, then skip that line (it is a comment or white space) Add that instruction to the instructMem list . If the instructMem size is 0 set the status to WAITING . Otherwise, set it to READY Copy the vector passed into the load method to the dataMem vector Return the current status . If a GritVM object is READY receiving a call to the run method, then the instructions can be evaluated . Otherwise, return the current status Evaluate the current instruction . After evaluation, move the current instruction forward the proper amount 1 for regular instructions Y for jumps if a jump is triggered (where Y l-0, if Y is 0, set status to ERRORED and return run method) . Set status to HALTED if the last instruction was HALT or the last instruction has been eached Return the current status Abstract Class Methods There will be an abstract class provided for your GritVM class to inherit from. The following methods must be defined STATUS load (const std: :string filename, const std::vector &initialMemory) This method loads the GVM program into the GritVM object and copies initialMemory into the data n memory. Retums the curent machine status. Throws if file cannot be read. STATUS run ) This method starts the evaluation of the instructions. Retums the current machine status std: :vector getDataMem () Returns a copy of the current dataMem STATUS reset) Sets the accumulator to 0, clears the dataMem and instructMem, sets the machineStatus to WAITING. Other things in GritVMBase hpp/cpp Also provided in the base class files are the enums that define the various stats and instructions for the GritVM. There is an instruction struct for holding an instruction, and it's argument. There are also five helper methods for you. All of these methods are in the namespace GVMHelper std: :string statusToString (STATUS S) Converts a status value to a string version of that status. STATUS stringToStatus (std: :string s) Converts a string of a status value to an enum of that status. std::string instructionToString (INSTRUCTION SET S) Converts an instruction value to a string version of that instruction INSTRUCTION SET stringtoInstruction (std: :string S) Converts a string of an instruction value to an enum of that instruction. Instruction parseInstruction (std: :string GVMLine) Given a line of a GVM file, this function returns an Instruction struct containing the instruction enum and the long argument (if applicable) Examples Below are GritM vm; // Status: WAITING // Accumulator: 0 // Data Memory // **Instruction Memory * some examples of how your code should run vm.load ("altseq. GVM", inMem) // Status: READY // Accumulator: 0 // Data Memory // Location 0 15 // **Instruction Memory * // Instruction 0 CHECKMEM 1 // Instruction 1 CLFAR 0 // Instruction 2: ADDCONST 1 // Instruction 3: INSERT 1 // Instruction 4 INSERT 2 // Instruction 5 AT 0 // Instruction 6 ADDCONST 1 // Instruction 7 SUBMEM 2 // Instruction 8: JUMPNZERO 2 // Instruction 9 JUMPZERO 9 // Instruction 10 CLEAR 0 // Instruction 11: AT 1 // Instruction 12: MULCONST -2 // Instruction 13: SET 1 // Instruction 14: AT 2 // Instruction 15: ADDCONST 1 // Instruction 16: SET 2 // Instruction 17: JUMPREL -12 // Instruction 18: AT 1 // Instruction 19: MULCONST 3 // Instruction 20 ADDCONST 4 // Instruction 21: SET 1 // Instruction 22: HALT 0 vm. run ) // Status: HALTED ator -98300 // *Data Memory // Location 0 15 // Location 1 -98300 // Location 2: 16 // *Instruction Memory // Instruction 0 CHECKMEM 1 // Instruction 1: CLEAR 0 // Instruction 2 ADDCONST 1 // Instruction 3: INSERT 1 // Instruction 4 INSERT 2 // Instruction 5: AT 0 // Instruction 6: ADDCONST 1 // Instruction 7 SUBMEM 2 // Instruction 8: JUMPNZERO 2 // Instruction 9: JUMPZERO 9 // Instruction 10: CLEAR 0 // Instruction 11: AT 1 // Instruction 12: MULCONST -2 // Instruction 13: SET 1 // Instruction 14 AT 2 // Instruction 15 ADDCONST 1 // Instruction 16: SET 2 // Instruction 17 JUMPREL -12 // Instruction 18: AT 1 // Instruction 19: MULCONST 3 // Instruction 20: ADDCONST 4 // Instruction 21 SET 1 // Instruction 22: HALT 0 2 std::vector:: iterator it = dataMen.begin(); while (it != dataMem . end ( )) long item = (*it) ; cout :: iterator it-instructMen.begin(); while (it !- instructMem.end )) instruction item (*it) ; cout &initialMemory) This method loads the GVM program into the GritVM object and copies initialMemory into the data n memory. Retums the curent machine status. Throws if file cannot be read. STATUS run ) This method starts the evaluation of the instructions. Retums the current machine status std: :vector getDataMem () Returns a copy of the current dataMem STATUS reset) Sets the accumulator to 0, clears the dataMem and instructMem, sets the machineStatus to WAITING. Other things in GritVMBase hpp/cpp Also provided in the base class files are the enums that define the various stats and instructions for the GritVM. There is an instruction struct for holding an instruction, and it's argument. There are also five helper methods for you. All of these methods are in the namespace GVMHelper std: :string statusToString (STATUS S) Converts a status value to a string version of that status. STATUS stringToStatus (std: :string s) Converts a string of a status value to an enum of that status. std::string instructionToString (INSTRUCTION SET S) Converts an instruction value to a string version of that instruction INSTRUCTION SET stringtoInstruction (std: :string S) Converts a string of an instruction value to an enum of that instruction. Instruction parseInstruction (std: :string GVMLine) Given a line of a GVM file, this function returns an Instruction struct containing the instruction enum and the long argument (if applicable) Examples Below are GritM vm; // Status: WAITING // Accumulator: 0 // Data Memory // **Instruction Memory * some examples of how your code should run vm.load ("altseq. GVM", inMem) // Status: READY // Accumulator: 0 // Data Memory // Location 0 15 // **Instruction Memory * // Instruction 0 CHECKMEM 1 // Instruction 1 CLFAR 0 // Instruction 2: ADDCONST 1 // Instruction 3: INSERT 1 // Instruction 4 INSERT 2 // Instruction 5 AT 0 // Instruction 6 ADDCONST 1 // Instruction 7 SUBMEM 2 // Instruction 8: JUMPNZERO 2 // Instruction 9 JUMPZERO 9 // Instruction 10 CLEAR 0 // Instruction 11: AT 1 // Instruction 12: MULCONST -2 // Instruction 13: SET 1 // Instruction 14: AT 2 // Instruction 15: ADDCONST 1 // Instruction 16: SET 2 // Instruction 17: JUMPREL -12 // Instruction 18: AT 1 // Instruction 19: MULCONST 3 // Instruction 20 ADDCONST 4 // Instruction 21: SET 1 // Instruction 22: HALT 0 vm. run ) // Status: HALTED ator -98300 // *Data Memory // Location 0 15 // Location 1 -98300 // Location 2: 16 // *Instruction Memory // Instruction 0 CHECKMEM 1 // Instruction 1: CLEAR 0 // Instruction 2 ADDCONST 1 // Instruction 3: INSERT 1 // Instruction 4 INSERT 2 // Instruction 5: AT 0 // Instruction 6: ADDCONST 1 // Instruction 7 SUBMEM 2 // Instruction 8: JUMPNZERO 2 // Instruction 9: JUMPZERO 9 // Instruction 10: CLEAR 0 // Instruction 11: AT 1 // Instruction 12: MULCONST -2 // Instruction 13: SET 1 // Instruction 14 AT 2 // Instruction 15 ADDCONST 1 // Instruction 16: SET 2 // Instruction 17 JUMPREL -12 // Instruction 18: AT 1 // Instruction 19: MULCONST 3 // Instruction 20: ADDCONST 4 // Instruction 21 SET 1 // Instruction 22: HALT 0 2 std::vector:: iterator it = dataMen.begin(); while (it != dataMem . end ( )) long item = (*it) ; cout :: iterator it-instructMen.begin(); while (it !- instructMem.end )) instruction item (*it) ; cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions