Posted on 06-09-2006, by Tim
An Introduction to the LC-3 Assembly Language
The first step toward learning the LC-3 assembly language is to download the LC-3 Simulator.
For Windows: LC-3 Simulator (requires WinZip)
For Linux: LC-3 Simulator
Download, install, and you're good to go.
After installation, running the simulator should open two windows. (For this demonstration, I will be using the Windows version of the LC-3 Simulator.) Double-click on Simulate.exe in the directory to which you installed LC-3 to run the simulator.
The first window is the simulator itself.
The second window is the console.
The LC-3 Simulator Interface
Now that you've seen the interface, let's explain some of its features.
What are registers? Think of them as variables. You can store temporary data in the registers. There are 8 registers in total: R0, R1, R2, R3, R4, R5, R6, and R7. Some registers are reserved for certain tasks. (You should keep this in mind when viewing more complex tutorials.)
x3000? What is that?
x3000 is a memory location, or address. The LC-3 simulator supports 2^16 (or 65536) memory locations. Memory locations are used to store data and even the LC-3 commands themselves.
The rest of the interface will be explained in more advanced tutorials. Don't be worried.
Your first LC-3 program
Don't be frightened by the the complexity of the interface. You will get used to it with time.
Now it's time for you to write your own program. In Windows, you will use the LC3Edit program that comes with the simulator to program your assembly code. In Linux, you can use other text editors such as gedit or emacs. The Windows Editor looks something like this:
We are going to write a program that displays the string "Hello World" to the console. Here is the LC-3 program:
LEA R0, HELLO_WORLD
HELLO_WORLD .stringz "Hello World"
Don't worry right now about the meaning of the following code. This will be explained in time. For now, all you need to do is enter the above code into the editor.
After you enter the code, to go File -> Save As. Save the file as "hello_world.asm". "asm" is the default file extension for the LC-3 simulator. Once it is saved, we have only one more step to go: assemble the code.
In Windows, go to Translate -> Assemble to assemble the code. In Linux, run the command "lc3as hello_world.asm". If no errors appear, then you typed the code correctly. Now we can move on to running the program!
Now open up the simulator if it is not already open. On Linux, you would use the command "simpl hello_world.obj" (obj means "object code"; it was created when you assembled your program). Under the Windows Simulator go to File -> Load Program and select the file "hello_world.obj".
Now go to Execute -> Run (or press R5) to run your program. Look over to the console to see if your program output correctly. It should look something like this:
Grats, you've just written your own LC-3 program! You've finished the intro tutorial. Now it's time for you to move onto more complex concepts to become a true LC-3 programmer.
- Views: 50264