CS 270
CS 270 Documentation

Introduction to the LC3

Objectives of this Lab

  1. Understand the structure of the LC3
  2. Familiarize yourself with common uses of LC3 instructions
  3. Understand how to assemble and run programs in the LC3

What to turn in

You will get credit for this lab by completing the Recitation 9 Quiz in Canvas.

Opening the LC3

You can use the following command to open the LC3:

~cs270/lc3tools/lc3sim-tk &
Alternatively, for a command line version of the LC3:
~cs270/lc3tools/lc3sim
Given an assembly code file (.asm file), you can assemble it using the following command:
~cs270/lc3tools/lc3as file.asm
Your TA will show you how to add these to your path, so you can use the shortened versions of the commands to run the LC3.

Understanding the LC3

A set of files have been prepared to help familiarize you with the structure of the LC3 and common uses for individual instructions. Copy these files into your own directory with the following command:

cp ~cs270/Current/recitations/R9/src/* .
Investigate each of the files. The recitation also comes with a Makefile that will automatically assemble all .asm files in your directory. You can use 'make clean' to clear all .obj and .sym files when you are finished. The suggested order to view the files is a follows (you may check off files as you go):

struct.asm
add.asm
and.asm
not.asm
ldst.asm
ldisti.asm
lea.asm
br.asm
jsr.asm
trap.asm

Try it out

Now it's time to put what you learned to use. Create a file named mult.asm and copy this code into it:

	.ORIG x3000
IntMul			; Your code goes here
			; Solution has ~9 instructions
			; Don't use registers 5, 6, or 7
	HALT
; Try changing the .BLKW 1 to .FILL xNNNN where N is a hexadecimal value or #NNNN
; where N is a decimal value, this can save you time by not having to set these 
; values in the simulator every time you run your code. This is the only change 
; you should make to this section.
Param1	.BLKW 1		; Space to specify first parameter
Param2	.BLKW 1		; Space to specify second parameter
Result	.BLKW 1		; Space to store result
	.END

The program should assemble as is. When you run the program, set Param1 and Param2 to two values. When the subroutine is finished running, the value of the two numbers multiplied together should be stored in result. Remember that all values are hex. For example, 0x2 * 0x9 = 0x12. Use the simple, although inefficient algorithm, of repeated addition. Also make sure your code works for edge cases, such as 0 or a negative value for Param1. It is not required for your subroutine to work when Param2 is negative.
This subroutine is also valid for the first programming assignment, but make sure to changed the HALT to RET when you copy it over.