Question: Simulator Instructions : Use the starter code provided with this description. You will be adding methods to implement the instructions. You dont need to modify

Simulator Instructions: Use the starter code provided with this description. You will be adding methods to implement the instructions. You dont need to modify BitString class. You will need to comment and uncomment a few lines in Simulator class. Before you start writing code, become familiar with the existing code. Testing must be done in a class named ComputerTest and please use Junit 4 or Junit 5 testing framework. Submit Computer.java and ComputerTest.java files on Canvas. Follow the coding conventions provided in the starter code and dont rewrite or change any of the method signatures.

LC3 simulator starter code includes the following files:

  • BitString.java
  • Computer.java
  • Simulator.java

BitString: The simulation is based on the class BitString. The existing code provides many methods that can manipulate BitString objects for you and you dont need to write additional methods. A BitString contains an array of char, but the values in each char are 0 or 1. There is an associated length member that keeps track of how full the array is (anywhere from 0 to 16).

Simulator: The class Simulator includes a short LC3 program in two different forms, assembly language and binary. This program prints the numbers 9 down to 1 and halts. There is some test code to test NOT instruction so that you could use it to write other tests.

Computer: The Computer class uses BitString objects to represent the contents of all registers and memory locations. The memory and register file are treated as arrays of BitString. To execute a single instruction, you will generally need to use a couple of BitString objects out of the Computer object, convert them to integers, do some calculations on the integer and vice versa. By frequently displaying the Computer object during development, you can verify that individual instructions are behaving properly. Please remove the frequent display before submitting code.

The required instructions that you must implement are ADD, AND, LD, BR, OUT and HALT. To finish the simulation, you will need to at least do the following:

  • Add methods to execute the unimplemented instructions (like ADD, AND, LD, BR, OUT, HALT).
  • Complete NOT instruction to set the condition code
  • Complete other instructions that set the condition code
  • Modify the execute method in Computer class, so that it executes instructions until it runs into a HALT instruction.
  • Write JUnit test methods for each instruction in ComputerTest class other than OUT and HALT.

You can model ADD, AND, LD and BR after the NOT instruction provided. You will need to examine the bits in IR and modify memory, condition codes, registers, and the PC as the current instruction would if executed by the LC3.

For OUT and HALT, which would normally trigger trap routines, the simulator should instead perform the required action. In the case of HALT, the execute method should quit (by exiting its loop) and for OUT, a single character should appear on the IDE's console based on the ASCII code currently in R0.

Your program does not need to execute any other LC3 instructions, but your code should be general enough to work with similar assembly programs. You will note that the amount of memory available in the simulator is quite small - roughly 50 words. This is enough for running simple programs.

If you want to try other programs, the LC3 editor program will create a .bin file containing 0/1 strings for any assembly program that you compile. The trap vector and interrupt vector tables are not included in this simulation. We are also omitting input/output related hardware such as KBDR/KBSR and DDR/DSR.

As a general strategy, you might execute single-instruction programs to test the quality of your simulator before testing a multi-line program.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!