CS0447 Computer Organization and Assembly Language Programming

CS0447 Computer Organization and Assembly Language Programming

CS0447 Computer Organization and Assembly Language Programming

Spring-00

Worksheet on UNIX, XSPIM, and SPIM(10pts)

Name:______

  • Due at 4pm in Eberly 321 on Friday, Jan 28th (or in class previously).
  • This should be done in UNIX lab such as Benedum Hall 1077
  • Help will be available in Benedum Hall during the recitation time by your TA
  • Read text appendix A.9(pages A-38 - A-49).
  • Hand in only your worksheet in the back and extra sheets specified. Make sure the papers are stapled together.

Familiarizing yourself with UNIX

Unix, like DOS and Windows, is an operating system. It is an important operating system that is widely used.

Basic Commands

There is a document we can access that has a description of many important unix commands. This document is located at:

/afs/pitt.edu/public/info/pittdoc/

To get to this directory do the following:

  1. Log into Unix
  2. $cd /afs/pitt.edu/public/info/pittdoc/
  3. $more unix_commands.doc

At this point, complete question 1 in the worksheet in the back.

To get more familiar with unix commands you will now compile and run a small C++ program.

Copy a file from a directory to your directory

The file is named gauss1.c and it is located under the directory

/afs/pitt.edu/usr/moir/public/cs0447

Use the copy command (cp) as described in unix_commands sheet to copy this file to your directory.

Compile and run

Use g++ command, which invokes a C++ compiler, to compile gauss1.c.

$ g++ gauss1.c produces an executable file called a.out.

$ ./a.out executes this file.

Modify a file

Use the editor pico to make changes to the file:

$ pico gauss1.c

Pico is an easy editor to use. Note the help bar along the bottom of the screen (eg. ^X=control-X).

Change gauss1.c so that it prints hello to you before it asks for the 2 integers. Your name must be in this hello message.

Compile and run the new program.

Print

The lpr command is an Unix command normally used for printing ascii files.

$ lpr -PBH gauss1.c

sends the gauss1.c to the Benedum Hall computing lab printer.

Attach the printout to the worksheet to be graded.

Accessing XSPIM

XSPIM is a MIPS simulator that uses Xwindows. You can use xwindows only if you are using UNIX workstation. There is also a version of SPIM that does not use Xwindows. You can use SPIM by telnetting to unixs. This section is about XSPIM. Read the text pages A-40 – A-43.

  1. Log on to a CIS UNIX machine.
  2. Edit your .bash_profile file using an editor. Pico is a very easy editor to use. You will use it to enter your MIPS programs and other files. Type "pico <filename>" to start.

Note: Please be very careful with the next step. Do not make a mistake. If you do, you will not be able to log back into your account again.

In your .bash_profile, find the line that says PREPATH=$HOME/bin and add :~melhem/spim/bin to the end. Save .bash_profile.

  1. Logout of the system (type exit). Next time you log back on you should be able to run xspim.
  2. After you log out and log back on, enter the command

$startx

This will start xwindows.

  1. In one of the windows, enter the command

$xspim

  1. Using another window (press middle or right button of the mouse get another xterm), type pico, and enter the MIPS program on the following page:

######################################

# PROG1.S - FIRST PROGRAM IN MIPS #

#------###########

# This program says hello, finds out what 23 - 7 is & #

# prints the result. Finally it says bye and exits. #

################################################

#

# Declare Data

#

.data

str_hello: .asciiz "Hello\nFrom MIPS\n\n"

str_goodbye: .asciiz "\n\nGoodbye from MIPS!\n\n"

#

# Execute code starting at "main".

#

.text

main:

##### Print the string str_hello using system calls. #####

li $v0, 4 # Prepare to print a string with a system call.

la $a0, str_hello # Place address of str_hello in $a0.

syscall # Make the system call.

##### Place 7 and 23 in registers they can be subtracted #####

li $s0, 7 # Set $s0 = 7

li $s1, 23 # Set $s1 = 23

##### Do the subtraction #####

sub $s1, $s1, $s0 # $s1 = $s1 - $s0

##### Copy the result into the proper register for output #####

li $v0, 1 # Prepare to print an integer with a system call.

move $a0, $s0 # Put the value of $s0 in $a0.

syscall # Make the system call.

##### Say bye, much like we said hello. #####

li $v0, 4 # Prepare to print a string with a system call.

la $a0, str_goodbye # Place address of str_goodbye in $a0.

syscall # Make the system call.

##### Exit the program, by calling the proper syscall#####

li $v0, 10 # Prepare to exit with syscall of 10.

syscall # Make the system call.

#END OF PROGRAM#

  1. After you type in the above program, press control-X to exit. This will ask you to give a name to the above program. Call it prog1.s
  2. Now go back to the XSPIM window and load the program you just typed up. After loading, run the program, accepting the default values when prompted, and answer the questions below.

Questions: (put in the answers for questions 3-10 in worksheet in the back.) You may keep this part as help when doing your project.

  1. What is in register $v0? ______
  1. What is in register $a0? ______
  1. What is in the memory location pointed to by $a0?

______

  1. Find the machine language encoding of the first instruction 'li'. What is the machine

encoding? ______

  1. What is the address of the main routine? ______
  2. What is the address of the instruction 'sub $s1, $s1, $s0?' ______
  3. Set a breakpoint at this address by clicking on breakpoint and entering the address of the instruction. Run your program until it stops at the breakpoint. What is in register $s1 at this point? ______
  4. Finish running your program by clicking on continue. What is in register $s1? ______

Accessing SPIM

SPIM does not use xwindows. You can use SPIM if you telnet to unixs machines. The telnet command is as follows: telnet unixs.cis.pitt.edu

(Read text pages A-45 - 46 to get familiarized with spim commands).

After logging in to unixs, type

$spim

this will invoke spim.

You can view the spim commands by typing help or ?. Type load “prog1.s” to load your program. Then run it and answer the following questions:

Questions: (put the answers for 12-19 in your worksheet in the back).

  1. Use print $v0 to see what's in register $v0______
  1. Use print $a0 to see what's in register $a0______
  1. Use print <address> to see what's in the memory location pointed to by $a0 ______
  1. Use step to find the machine encoding of the first instruction 'li'. What instruction did spim convert this to? ______What is the machine encoding? ______.
  1. What is the address of the main routine? ______
  1. Continue using step to find the address of the instruction 'sub $s1, $s1, $s0.' What is this address? ______Set a breakpoint at this address by typing breakpoint <address>
  1. Type continue to finish running your program, then type run again to run until the breakpoint. Use print $s1 to see what’s in register $s1 ______
  1. Type continue to finish running your program. What is in register $s1? ______

Hand in Worksheet - CS447(00-2)

Name:______

  1. Briefly describe the following commands.

a)ls

b)more

c)cat

d)cp

e)rm

f)mv

g) lpr

  1. Submit a printout of your modified gauss1.c program.
  1. What is in register $v0? ______
  1. What is in register $a0? ______
  1. What is in the memory location pointed to by $a0? ______
  1. Find the machine language encoding of the first instruction 'li'. What is the machine encoding? ______
  1. What is the address of the main routine? ______
  2. What is the address of the instruction 'sub $s1, $s1, $s0?' ______
  3. Set a breakpoint at this address by clicking on breakpoint and entering the address of the instruction. Run your program until it stops at the breakpoint. What is in register $s1 at this point? ______
  4. Finish running your program by clicking on continue. What is in register $s1? ______
  5. Load the same program you typed up before into SPIM and run it.
  1. Use print $v0 to see what's in register $v0______
  1. Use print $a0 to see what's in register $a0______
  1. Use print <address> to see what's in the memory location pointed to by $a0 ______
  1. Use step to find the machine encoding of the first instruction 'li'. What instruction did spim convert this to? ______What is the machine encoding? ______.
  1. What is the address of the main routine? ______
  1. Continue using step to find the address of the instruction 'sub $s1, $s1, $s0.' What is this address? ______Set a breakpoint at this address by typing breakpoint <address>
  1. Type continue to finish running your program, then type run again to run until the breakpoint. Use print $s1 to see what’s in register $s1 ______
  1. Type continue to finish running your program. What is in register $s1? ______