CS 270
CS 270 Documentation
!doctype html> CS270 Recitation

LC3 Command Line Simulator

What to turn in

You will get credit for this recitation by completing the Recitation 11 Quiz in Canvas.

Go through all the instructions before starting the quiz.

Goals

  1. Get experience working in a command line environment
  2. Get a better understand how the automated grading system works
  3. Use this experience to make working with other comamand line interfaces easier.

Working with the LC3 command line simulator

So far most of you have probably only interacted with the GUI version of the LC3 simulator. This simulator is useful, but sometimes you can run your code more efficiently with the command line version. Today you will learn how to set and display values in the LC3s registers and memory, set breakpoints, execute the code, as well as automate the entire process. The automation of the LC3 simulator is what can be most convenient, imagine you need to set the values of multiple registers and memory locations (labels) before every run of your program. This can be done in the GUI based simulator, but is slow and tedious. With the command line version you only need to build the commands once, and then using them in the future is easy.

lc3sim documentation

To get information on how to interact with the lc3sim you first need to run the simulator. This can be done by typing:
~cs270/lc3tools/lc3sim
Once inside the simulator entering the character h will bring up the help documentation. use this info to answer the questions in the Recitation 11 Quiz. You will want to have some lc3 code to experiment in the simulator with, I would suggest using the code provided in R9 or your code from P5/6.

Tip: the simulator is currently very picky when it comes to entering commands, this means that if you make an error and need to use the backspace or arrow keys your command will not be correctly interpreted. Simply hit enter and try again with the new prompt line.

Using a script with the lc3sim

Now that you have an idea about how to operate the lc3sim its time to automate the process. Scripts are just a series of commands that automate the executions of tasks. To build a script for the lc3sim all we need to do is create a file and fill it with the same commands that we would type into the lc3sim. Here is an example of a basic script:
file P5.obj
memory Option 2
break set x300C
continue
translate Result
quit
You can see this script first loads the P5.obj executable, sets the memory location associated with the label Option to the value 2, sets a breakpoint at location x300c, runs the code until the breakpoint is reached, prints the value of the label Result, and exits. The last question in the quiz asks you to figure out how to use the script with the lc3sim.

Here is a link to a page that Fritz built with some more info on the lc3sim. lc3sim

Apply your new knowledge

Now that you are a bit more familiar with how the lc3sim works, look at the results from P5 and see if you have a better understanding of how the grading works. You should also try to recreate the input and output for a couple of the P5 tests.

Finally, a lot of what you have learned with the lc3sim applies to working with gdb, a very powerful debugging tool for C. With any time you have left open gdb by typing: gdb then look though its documentation by tping: help. You can then experiment in the lc3sim with your lc3 code or in gdb with your C code from previous assignments.