The project has two goals - (i) introduce you to the SPIM simulator for the MIPS instruction set, (ii) give you some practice writing MIPS assembly programs.
Exercise
1 - Introduction to SPIM (10 points)
This
exercise involves executing a MIPS assembly program on the SPIM
simulator.
Before beginning this exercise you should have read Appendix A in the
textbook
(specifically, the part of the appendix related to SPIM). Download the
program sort.s from the class home page into your home
directory.
Make sure you read the information on the web page for Assignment 2
regarding
the project.
There are two ways to use the SPIM simulator on UNIX based systems: (1) via a command line interface, or (2) using a X windows interface. The command line interface is invoked through the command "spim" whereas the X windows interface is invoked via the command "xspim". The version of SPIM for PCs (PCSpim) is window-based. The description below pertains to XSPIM. However, it is equally applicable to PCSpim.
On your UNIX workstation, bring up XSPIM by typing:
xspim &
Notice the
following points
while using XSPIM:
1.
2.
3.
4.
addi $t1,$t1,-1
Submit your answers to question 2 and question 4 above.
Exercise
2 (90 points)
Write
and test a MIPS assembly program that given two matices, M1 and M2,
first transposes M2, and then multiplies it with the second matrix. You
should implement four routines:
·main()
Invoke the matrix_transpose procedure to transpose a
given matrix. Then multiply the transposed matrix with another
given matrix using the matrix_multiply procedure. Finally,
print out the product matrix.
·Matrix_multiply(r1,c1,A,r2,c2,B,C)
oThis
procedure computes the product of two matrices A and B
and
stores the result in the matrix C.
oMatrix
A has r1 rows and c1 columns and matrix B
has
r2 rows and c2 columns.
oHere
A, B, and C are the memory addresses at which the
matrices
A, B, and C are stored. Assume that matrices are
stored
in memory in row-major fashion.
oNote
that matrix C will have r1 rows and c2 columns
oMatrix_multiply
should invoke the procedure Inner_product() while computing the
product of A and B.
·Inner_product(r,num_columns1,M,c,num_rows,num_columns2,N)
oThis
procedure multiplies row r of matrix M with column c
of matrix N. num_columns1 is the number of columns in
each
row of M, whereas num_rows is the number of rows in
each
column of N and num_columns2is the number of columns in N
oIf num_rows
is not equal to num_columns1 this program should print an error
message and exit.
oThis
procedure returns an integer (the inner product) to the calling
procedure.
The
assignment web page contains the following additional information:
·The
two matrices to be multiplied
·How
to declare these matrices in your assembly program
·The
result matrix. You can compare your result against this matrix to
verify
the correctness of your program.
·A
C program matrix.c corresponding to a high-level language
implementation
of this program.
Test your program
by running
it using SPIM/XSPIM. To
get full credit, you must invoke the procedures correctly within your
program,
i.e., you must pass arguments to the procedures matrix_multiply
and inner_product,
save and restore registers at the procedure entry and/or exit points,
and
return the results of inner_product
to the matrix_multiply
procedure correctly. Explain what procedure call convention you're
following
in your code, i.e., whether it is caller save or callee save or another
convention (e.g., the MIPS convention).
Submit (1) your assembly program. Your program must be well commented (2) A brief description of the procedure call conventions you are following (3) A hardcopy output showing that your program works correctly. In Windows, you can save the results of your session using the "Save Log File" menu option. In UNIX, to capture the output of your program (assuming it's called matrix.s) type
spim -file matrix.s
NOTE:
spim and xspim are installed on both the Mason cluster and the machines
in the IT&E lab. To obtain PCSpim follow the link from the class
web
page.
Preparation for Assignment 3
For
this exercise you will have to obtain a count of how often each
instruction
in the programs matrix.s
and sort.s
is executed. You will have to produce a table similar to the table
below
for each program.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
How do you think you would come up with these counts? (HINT: There is a brute force method using SPIM and also a ``smart'' method. You are expected to use the smart method.)
NOTE:
You
do not have to submit the answer to this question. This is only to give
you a preview of what you will have to do for the next assignment, and
to give you something to think about.
LATE
SUBMISSION POLICY
No late projects will be accepted unless prearranged with the
instructor.