This lab is scheduled for the week of 3 April - 4 April.
This week we'll look at:
Start off creating and then connecting to a directory called csci/255/lab8.
You're going to write an assembly language program
for the LC-2. The program will set the values of
registers R0
, R1
, and
R2
based on the values of
registers R3
and R4
.
Your program should not change the
values of R3
and R4
;
however, it is free to use
R5
, R6
, and
R7
as "scratch" registers.
You must be sure your is loaded at x3000.
Here is the C-code you are supposed to implement:
R0 = !R3 ;
R1 = ( R3 | 0x4444) & ~0x1111 ;
R2 = R3 || R4 ;
Keep in mind that the C
!
and ||
operators
always return either 0, for false, or 1, for true.
Your code should do likewise. For example,
if the value of R3
is 6 and the
value of R4
is 5; your code
should set R0
to 0
and R2
to 1.
We're going to make this a little easier for you by giving you a program that performs the first of the three statements:
R0 = !R3 ;
Use the following Linux commands to obtain a copy of this program, to assemble the program, and to then list the files contained in your lab8 directory:
If you don't see a file called lab8.obj in your directory, you need to get the attention of the instructor.
If you prefer, you can use Windows. Start by downloading the lab files in either ZIP or Windows EXE format. However, if you use windows, you must FTP your completed program back to your ~/csci/255/lab8 directory.
Start the LC/2 simulator by typing the command "lc2sim &" and load the object file lab8.obj. Next run the program.
Notice that this program really doesn't have any I/O:
It doesn't an read initial value for R3
,
and it doesn't print the final value for R0
.
To set R3
you have to use the
thenSet Value introduced in
Lab 5.
To discover the value of R0
, just look
at the LC/2 register display at the top of the
simulator's window.
Test out the program with R3
set to
the following values: 5, 0, and -5.
You will probably want to set a breakpoint at the
HALT trap to make sure the values in
R0
and R1
are not changed
by the HALT trap.
Show the instructor the result of running the program with
R3
equal to -5.
Now you need to write the remaining two lines of code for your program. Think about the code you are going to write and use pico to modify your program. If you've forgotten how to use pico, you can review Lab 2 of CSCI 107. If you have ever used pico, you can study Lab 2 of CSCI 107. If you have ever used pico.
You will undoubtedly need to cycle through pico, lc2asm, and lc2sim as your debug your program. The cycle will progress a bit faster if you keep lc2sim running while you pico and lc2asm.
Be sure to test out your program on a few different and interesting input combinations.
Presently, your program ends with a HALT trap. Make your program into a subroutine by replacing the HALT with a RET.
Now you need something to call your newly subroutinified Lab 8 program. Copy the object file /usr/local/csci/lab8/main8.obj into your directory and load it into lc2sim. This newly loaded program will prompt you for input, call your subroutine a location x3000, and display its results. It will will repeat this process until you type a ^D, control-D or ASCII EOT.
Try running the main program to give your code a more thorough testing.
When you are done, exit the simulator and log out of the Linux workstation. Do not delete your files. Your lab instructor will examine them later.
Your lab instructor can verified that your correctly copied your program by executing the following command on woodfin.