Loading Programs

  1. Introduction
  2. Loading Programs
  3. Pseudo Code

In this section, we will learn how load assembly files into PennSim and execute them. We first need an operating system (OS) loaded. I will not go into the details, but like your computer, there are applications and then there is the operating system. So similar to your computer, PennSim, like the little computer it is, also needs an operating system.

The operating system is just another assmbly file that is assembled and loaded into the simulator. The assembly code for the OS is shown below in "lc3_os.asm". We won't worry to much about what the code means, yet. Our objective as of right now is to assemble and load it and to get a simple program running. The simple program is going to be a seperate assembly file, the code for "lc3_first.asm". What you will need to create the assembly file is an advanced text editor. For windows I like to use Notepad++. You can use a different text editor, but for this tutorial, I will be using Notepad++.

Open your text editor, and copy / paste the operating system assembly code shown in the first code box into the editor. Click save, but when prompted to choose a save type, select "Assembly Language Source File (*.asm)", or look for which ever shows as a ".asm" file. Also, make sure that the assembly file is saved in the same location as the PennSim application. The "as" and "ld" commands will not work for a file not in the same folder. Do the same thing for the code shown in the second code box. Once you have done that you should have two assembly files and the PennSim application in the same folder, like in figure 2-1 below.
lc3 window
Figure 2-1: Files.

Next, open PennSim and assemble and load the operating system and the lc3_first.asm script. To do this, we will first assemble each script. Figure 2-2 below shows how to do that. The command to assemble is "as", as you can see in Figure 2-2 (A), "as lc3_first.asm" is what we use to assemble lc3_first.asm. Similarly the OS is assembled in part B. This is done from the command line.
lc3 window
Figure 2-2: Assembling script.

We should see the output in figure 2-2, if there are any errors make sure that the scripts were copied correctly and also make sure they are in the same folder as PennSim. When the scripts are succesffully assembled, PennSim will create a symbol table (extension .sym) and an object file (extension .obj). The symbol table is a list of all the symbols used in the script while the object file will be what is loaded and ran in PennSim. After assembling, our PennSim folder should look like figure 2-3.
lc3 window
Figure 2-3: Files after assembling.

Next, we load the OS and our program using the "ld" command. For this section, we will be using "lc3_first.asm", but this can be replaced with any other user-made script. Later we will go through what is required to create a script. As of right now, we only want to get "lc3_first.asm" working to get the basics of using PennSim down.

To load, we need to load the object file, not the assembly file. The commands we will use are "ld lc3_os.obj" and "ld lc3_first.obj". Figure 2-4 showns the commands in PennSim.
lc3 window
Figure 2-4: Loading scripts.

After loading both the OS and the program, clicking the "Continue" button will run the script. The button is circled in red in figure 2-5 and the output from the program can be seen in the terminal. If this section has been followed correctly then that is what we should see.
lc3 window
Figure 2-5: End result.

In the next section, we will begin looking at creating our own script. To do this we will begin with talking about the Psuedo Code.

Next Section: Pseudo Code