LC-3 Simulators

We have a few LC-3 simulators available to use. Here is a brief description of each on found at http://www.cosc.brocku.ca/Offerings/2P12/Tools/. You will need to have one of these running on your computer in order to complete the fourth assignment.

LC3 Sim - Java

For this simulator you will expand the zip file into a directory. Launching the contained jar file will launch the assembler/simulator. To assemble and simulate you must enter commands in the small rectangular area near the top of the window. To assemble a source file you have created (created by a text editor) and that is placed in the directory you must enter the command as yourfile.asm. It will issue error messages when appropriate and when the assembly is complete will create a machine language version named yourfile.obj. Before you can test your program out you must load the lc3 operating system with the command load lc3os.obj. Then you load the object file for simulation with the command load yourfile.obj. At this point you can set the starting address for execution with the command set pc x3000 (assuming your program uses .orig x3000) or by modifying the PC as shown in the set of registers. At this point you can execute instruction by instruction with the Step button, or set breakpoints by clicking on checkboxes adjacent to instructions, and then execute up to the next breakpoint with the Continue button.

lc3tools - MacOS - Linux

Expand the lc3tools zip file into its directory. You must prepare the executables with the make command. If this is successful you will have created an lc3as executable for assembling programs and an lc3sim-tk executable for simuluation. To execute these executables you will enter ./lc3as or ./lc3sim-tk (unless you include the directory in the executable path on your computer in which case the ./ is not needed). So in most cases to assemble you would use ./lc3as yourfile.asm and to simulate you would use ./lc3sim-tk to start the simulator and then invoke Browse to load yourfile.obj. This simulator automatically loads the lc3 operating system so there is no need to explicitly load it as is required with the Java simulator. When the simulator is loaded and you Browse to load an object file the PC is automatically set to the origin address from the program. You can then execute instructions one at a time, set breakpoints by double clicking on a line of code, or execute up to a breakpoint with the Continue or Finish button.

LC301 - Windows

The downloaded executable LC301.exe will produce two windows programs: LC3 Edit and LC3 Simulate. The LC3 Edit will allow you to edit source files and contains a menu item to assemble the file. The files should be saved with the .asm suffix. When Assembly is invoked it will display assembly errors as appropriate and if the assembly is successful will produce a machine language object file with the .obj suffix. The LC3 Simulate will allow you to load object files for execution and the PC is set to the program start defined by the .orig line in the source code. Again the LC3 operating system is automatically provided and you do not need to load it manually. You can execute instructions one at a time from the Execute menu or set breakpoints by double clicking on an instruction and continuing execution with the Run command in the Execute menu.

Running a Sample Program

You should either type in a simple LC-3 program or download one from the http://www.cosc.brocku.ca/Offerings/2P12/ExamplesLC3/ sample programs directory, such as add.asm, assemble it, and execute it to verify successful operation and familiarize yourself with the programming environment.

Extended Traps

These will be discussed in the next class. These are trap routines written by a Brock student many years ago. They provide for such things as reading an integer, printing an integer, multiplying two integers, dividing two integers, and subtracting two integers to simplofy writing programs that need these facilities.

use trap xfb for read integer
use trap xfc for print integer
use trap xfd for subtraction
use trap xfe for multiplication
use trap xff for division

trap xfb will take care of ascii integers to integer conversion and places the integer result in R0
trap xfc will take care of integer to ascii conversion and will print the integer contained in R0
trap xfd will subtract R1 from R0 and places the result in R0
trap xfe will multiply R0 by R1 placing the result in R0
trap xff will divide R0 by R1 and store the quotient in R0 and the remainder in R1

In order to use these traps you will have to load the newtrapsV2.obj file before you load your program object file. The source file newtrapsV2.asm is also available so you can view the source code if you wish, and assemble it to produce the object file rather than download the object file. Both are found in the LC3 Sample programs directory. Here is a small program you can use to test using the newtraps. It will require entering two integers (no prompts are displayed) and will print out the resulting product of the two values.

       .orig   x3000
       trap    xfb        ; read an int
       add     r1,r0,#0   ; copy to r1
       trap    xfb        ; read another int
       trap    xfe        ; multiply the ints
       trap    xfc        ; print product
       halt
       .end