Spring 2001 CSCI 255 Lab 5

This lab is scheduled for the week of 19 February - 24 February.

Goals and Methods

This week you'll learn a couple of things:
(1), how to use a Linux computer; and
(2), how the LC-2 simulator interprets machine language problem.
The second thing may not be as much fun as the first.
We will use the machine language example program
in section 5.4.2 of the text book with the simulator.

We are not going to have detailed descriptions of the
Linux login procedure in this handout. Your lab
instructor will demonstrate that for you.

If you are a Linux guru,
go help someone who is not a Linux guru.

Logging on

Under the direction of the lab instructor, log onto
the Linux workstation and start up two terminal windows.
Use the userid and password distributed in class.

If you have "lost" the userid and password, the
lab instructor can reset your account.

Note to lab instructor: Use the program
/usr/local/etc/resetuser on woodfin
to reset lost accounts.

Setting mail forwarding

If you do not intend to read email on the UNCA CSCI
computers, use the program pico to create
a file called .forward in your home directory.
This file should contain your real email
address and nothing else.
pico is the text editing part of pine,
the mail program you briefly used in
Lab 2 of CSCI 107.

Creating a directory under Unix

Use the following Unix commands to create a read-protected
subdirectory called csci/255/lab5.
The first command, mkdir, creates the directory.
The second command, chmod, protects your subdirectory
csci, so that normally only you can access its contents.
For more information on Unix file protection review
Paula Edmiston's CSCI 107 tutorial on The UNIX Operating System.

mkdir -p csci/255/lab5

chmod go-rwx csci

Although the above chmod would normally remove
read, write, and execute (rwx) permission for
group members and others (go) for your directory csci;
on the UNCA CSCI
workstations there are special programs that allow all
UNCA faculty to access student files stored within the
csci directory.

Copying files under Unix

Connect to your lab directory.
Next use the Unix cp command to copy several files
to your directory. Be sure to note the single period at the
end of this command line. The period is the way Unix and DOS
represent the current directory.

cd csci/255/lab5

cp /usr/local/csci/255/lab5/* .

Checking it out

Now use the pwd and ls, with
the -l option, commands to
verify your directory creation and file transfer.
You should see something like the following:

It is not necessary for the lab instructor to view the output
of these commands. The existence of your csci/255/lab5
directory and the above files will be checked with
Unix shell scripts.

Giving the other person a chance

Log out of the Linux workstation and give your
teammate an opportunity to perform the lab up to this point.

Running the LC-2 simulator -- example 1

Section 5.4.2 of the textbook contains a
machine language program for adding twelve numbers.
We've modified that program so that it will only
add three number (5, 10, and 15) and it will store
the result in memory.
The modified version
of the program should be stored in your
lab directory as
ch5_ex1.bin and ch5_ex1.obj.
The binary version of the program, which can be
edited using pico, is stored in
ch5_ex1.bin.
The object version of the file, suitable for
use with the LC-2 simulator is stored in
ch5_ex1.obj.
You can use the LC-2 conversion program
lc2concert to transform a
LC-2 binary file into an LC-2 object file.
We've already done that for you in this lab.

Type the command "lc2sim &" to start
the simulator.
You should see both a Simulator window and
a Console window.

At the top of the simulator window, you will see a
command bar.
Below that you will see a display of the registers
of the simulated computer.
In the middle of the window, you will see the contents
of the simulated memory.

Loading a program

Press on the File menu button and then
select Load Program ... from
the pulldown menu.
Use the File Selection dialog to load the machine language program
ch5_ex1.obj.

You should now see the machine language program in the
Memory section of the simulator window.
A typical line will look like:

[3002]:0101010010100000 54a0 ; and R2, R2, $0000

The leftmost hexadecimal number, 3002, is the address of the memory
location. The remaining three fields on the line give the
contents of the memory location in different formats.
First, the number is given as a 16-bit binary number;
then, it is displayed in hexadecimal; and finally
the location is interpreted as an LC-2 machine instruction.
In this case the instruction opcode is and,
the destination is R2, and the two source operands
are R2 and the constant 0.

Stepping through a program

Your job is to step through the program until
it terminates at instruction 300a.
Use the Run »
Step Program ... menu selection
to execute a single instruction.
For each executed instruction, write down the follow following
five pieces of information:

Address

Operation

Destination register or memory location

Value stored in destination

Values of one-bit N, Z, and P registers

If the instruction modifies the program counter, you
should write down the new value of the PC.
To help you out, we are providing a
fill-in check-off form for
lab 5 that has completed entries for the
first few instructions.
Give this form to your instructor at the end of the lab.

Going home

When you are done, exit the simulator and
log out of the Linux workstation.