MIME-Version: 1.0 Server: CERN/3.0 Date: Monday, 16-Dec-96 23:18:38 GMT Content-Type: text/html Content-Length: 8016 Last-Modified: Monday, 13-Mar-95 14:33:34 GMT Project 1: Martix Products [Back to CS314 Home Page]

Project 1: Martix Products

Date Assigned: February 14, 1994
Date Due: February 28, 1994

Introduction

This project involves writing a small assembly language program for multiplying matrices. Your program will gets its input from and send its output to the BasePak runtime window.

Specs

Overview

Compute the matrix product AB---technically, AB mod 2^16 --- where A and B are matrices of 16-bit unsigned integers. The minimum matrix size will be 1x1, and the maximum matrix size will be 16x16.

Input parameters

-------------------------------------------------------------------------------------------------------------
A    m x n matrix of 16-bit unsigned integers     A is the first matrix in the product.     
B    n x p matrix of 16-bit unsigned integers     B is the second matrix in the product.    
m    unsigned 8-bit integer                       m is the number of rows in A             
n    unsigned 8-bit integer                       n is the number of columns in A and the number of rows in B.                      
p    unsigned 8-bit integer                       p is the number of columns in B          

            m, n, and p satisfy 1 <= m,n,p <= 16
-------------------------------------------------------------------------------------------------------------


Output parameters

-------------------------------------------------------------------------
C     m x p matrix of 16-bit unsigned integers         C = AB mod 2^16
-------------------------------------------------------------------------


Arithmetic

Do all arithmetic over integers mod 2^16, i.e., use unsigned 16-bit integer multiplication and addition and take only the low-order word of multiplication results.

User interface

The "user interface" of your program will be minimal---this is an assembly language program, after all. Your program should prompt the user for the parameters m, n, and p, successively, then allow the user to enter the values of the elements of the matrix, A, then the values of the matrix B. After these values have been entered, your program should output the matrices A and B and then output the result matrix C. (All numerical input and output should be in base 10.)

Matrices should be output in standard order, i.e., a row of elements in the matrix should correspond to a row of numbers on the screen. For example, if A were a 2 x 2 matrix with elements a11 = 1, a12 = 2, a21 = 3, and a22 = 4, then A would be output as:

    1 2
    3 4
Matrices should be input by prompting the user for elements, one at a time, in the same order in which they would be output. The text of the prompt should include the matrix name and the indices of the element currently being prompted for. For example, the matrix A given above would be entered via the following exchange (underlined text indicates the program's output, non-underlined text indicates the user's input):
  A[1][1]: 1
  A[1][2]: 2
  A[2][1]: 3
  A[2][2]: 4

Sample Run

A run of your program should look something like the following:
m: 2
n: 3
p: 4
A[1][1]: 0
A[1][2]: 1
A[1][3]: 2
A[2][1]: 3
A[2][2]: 4

A[2][3]: 5 B[1][1]: 10 B[1][2]: 11 B[1][3]: 12 B[1][4]: 13 B[2][1]: 14 B[2][2]: 15 B[2][3]: 16 B[2][4]: 17 B[3][1]: 18 B[3][2]: 65510 B[3][3]: 20 B[3][4]: 21 A: 0 1 2 3 4 5 B: 10 11 12 13 14 15 16 17 18 65510 20 21 Result (A*B): 50 65499 56 59 176 65499 200 212

which corresponds to:

Documentation

The usual documentation guidelines (always explain how you're using registers, use symbolic constants whenever possible, state the input and output parameters of all subroutines, etc.) apply. Your program should have at least 3 subroutines, one for inputting matrices, one for printing matrices, one for multiplying the matrices. Each subroutine should begin with a header that looks like this:
  ;-------------------------------------------------------------------------
  ;
  ; <Name of function>
  ;
  ; 
  ; Synopsis
  ;  <A brief description of what the function does, who calls it,
  ;   why, and any exceptional conditions.>
  ;
  ; HLL description:
  ;
  ;  <Put in high level language (e.g., C, pascal, pseudo-code)
  ;   description of routine here.>
  ;
  ; Register usage:
  ;  <Map out what registers are used for>
  ;
  ; Input Conditions:
  ;  <What should the format of the registers and stack be on entry
  ;   to the routine?>
  ;
  ; Output Conditions:
  ;  <What will the format of the registers and stack be when the
  ;   routine returns?>
  ;
  ; Stack frame:
  ;  <What does the stack frame look like? For example:>
  ;
  ;    Saved Registers
  ;       A6 -->  Old A6             0(A6)
  ;               Return Address     4(A6)
  ;               Param 1            8(A6)
  ;               Param 2           12(A6)
  ;    
  ;-------------------------------------------------------------------------


The subroutine code should immediately follow the subroutine header. Try to comment each line and use block comments and blank spaces to separate logical sections of the subroutine. For example, here's the code of a routine that swaps the two registers D0 and D1 if D1 < D0.
  SWAP:  
         ;
         ; Prolog: Save registers, set up stack frame
         ;
         LINK      A6,#0       ; set frame pointer -- no locals
         MOVEM.L   D2,-(SP)    ; Save registers we'll use.
   
         ;
         ; Compare D0 and D1 to see if we need to do anything.
         ; If not, then just jump to epilog and leave.
         ;
         CMP       D1,D0
         BLT       DONE
   
         ;
         ; If we get here, D1 < D0.
         ; Swap the contents of D0 and D1, using D2 as a scratch register
         ;
         MOVE.L    D0,D2       ; tmp:= D0
         MOVE.L    D1,D0       ; D0:= D1
         MOVE.L    D2,D0       ; D0:= tmp
   
         ;
         ; Epilog: Restore registers, clean up stack frame, return.
         ;
  DONE:  MOVEM.L  (SP)+,D2     ; Restore registers, etc.
         UNLK  A6
         RTS


Try to give a high level description in the function header, a more detailed description in the block comments, and a blow-by-blow in the individual line comments. Don't just repeat what the code says, if possible.

In addition, for this project, be sure you document the following aspects of your program:

Misc.

Your program should check that the values of m, n, and p supplied by the user fall within the allowable range.

You'll probably need to adapt the 32-bit signed decimal i/o routines in the BasePak library for use as 16-bit unsigned routines. (For this project, simply taking the low-order word of the return from decin_long would be acceptable for inputting 16-bit unsigned integers (though that wouldn't be a such a great idea in a real program), and using decout_long will work for outputting 16-bit unsigned integers as long as you remember to clear the high word of d0.)

Submitting

Hand in the following to the consulting office: [Back to CS314 Home Page]