The purpose of this tutorial is to step through the process of using LC-3 Edit to convert LC-3 binary/hex code into an object file readable by PennSim. This tutorial assumes you have read the PennSim Guide and are familiar with the basics of using PennSim.
A quick discussion of the various file types you will encounter will be helpful. These file types are .obj, .bin, .hex, .asm.
These files are the "machine" code that can be executed by the LC-3 simulator. It contains sequences of 16-bit binary values that correspond to LC-3 instructions. These files are unreadable in a text editor and will be created for you either by LC-3 Edit or PennSim.
These files contain ASCII representations of LC-3 binary code. One line of 16 ASCII 1s and 0s corresponds to an LC-3 instruction. For example, the line 0001000000100001 corresponds to the LC-3 assembly instruction ADD R0, R0, #1. Please not that these files are different than .obj files in that the 1s and 0s in a .bin file are ASCII characters instead of raw binary code. The .bin file must be converted to a .obj file (by using LC-3 Edit).
These files contain ASCII representations of LC-3 hex code. One line of 4 hex digits corresponds to an LC-3 instruction. For example, the line 1021 corresponds to the LC-3 assembly instruction ADD R0, R0, #1 (see above for the binary version). As this is also an ASCII representation, a .hex file myst be converted to a .obj file before the simulator can read them.
These files contain LC-3 assembly code. Each line contains a single assembly instruction. For example, ADD R0, R0, #1 is a single assembly instruction. In order to convert a .asm file into a .obj file, it must be run through an assembler. This should be done through PennSim and is discussed in the PennSim Guide.
A few notes:
You can download LC-3 Edit here. Unzip the lc3edit_301.zip file in order to run the program. Double click on the icon to start.
Write your binary or hexadecimal code in the blank editing screen. Here is some example code you can copy in to the editor:
0011000000000000 ;start at x3000
0001101010100001 ;R5 <= R2 + 1
Make sure you save your code by pressing the Save button. Do this often so you do not lose any of your work. For correct record keeping, you should save your file with the correct file extension: .bin for binary code, .hex for hexadecimal code, .asm for assembly code.
You can also open existing source by pressing the Open button.
PennSim requires an object file (a file with a .obj extension ) to execute. To convert your binary or hexadecimal source code into an object file, press the corresponding conversion button (B for binary, X for hexadecimal).
LC-3 Edit will output what it is doing in its console at the bottom of the screen. If there are errors, it will output the line number and error in the console screen. If there are no errors, LC-3 Edit will print "Convert Complete." An object file with the same file name as your source (but with a .obj extension) will now be in the same directory that you saved your code.
Open PennSim, select File -> Open .obj file. In the open file chooser, navigate to the directory where your .obj file was created, and open it. This will load your source code is now loaded in the simulator. PennSim will output an error saying it cannot find a symbol file. You can ignore this.
To run your code, first set the PC register to the starting address of your code (probably x3000) by typing set PC x3000. Your LC-3 program has now been successfully loaded into PennSim and is ready for execution.