This lab is scheduled for 27 & 28 February.
This week you'll learn how the LC-2 simulator interprets machine language problem. We will use the machine language example program in section 5.4.2 of the text book with the simulator.
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 "sudo /usr/local/etc/resetuser" on woodfin to reset lost accounts.
Use the following Unix commands to create a read-protected subdirectory called csci/255/lab5.
Connect to your lab directory. and copy the lab files to your directory. Note the single period at the end of this command line. The period is the way Unix and DOS represent the current directory.
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:
joe% pwd /woodfin/facusers/brock/csci/255/lab5 joe% ls -l total 8 -r--r--r-- 1 brock man 512 Feb 19 11:43 ch5_ex1.bin -r--r--r-- 1 brock man 60 Feb 19 11:43 ch5_ex1.obj
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.
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.
Press on the
menu button and then select 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.
Your job is to step through the program until it terminates at instruction 300a. Use the
» menu selection to execute a single instruction. For each executed instruction, write down the follow following five pieces of information: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.
Let's begin my modifying one of the numbers to be added.
Use the
Go to the text field for the register and memory location and type in x3010, the address of the memory location you wish to modify. Press the tab key and then type in a new value for this memory location.
Because the PC changed when you executed the program, you must restore it to point to location 3000. Again use
» to do this. This time type PC as the register to be changed.Now re-execute your program.
Sometimes it is necessary to modify program code. Suppose you wanted this program to add the contents of the five memory locations from 3010 to 3014; that is, you want it to add in two more numbers. By modifying one machine instruction you can make that change.
Modify that one instruction and write on the check off sheet the address and new value for that instruction. If you need some help, start by thinking how we ensured the original program added only three numbers.
Look for the one instruction that sets the initial value of the loop counter. Change the one field of that instruction that contains the initial value.
When you are done, exit the simulator and log out of the Linux workstation.