	page 132,66,0,6
;********************************************
;Motorola Austin DSP Operation  June 30, 1988
;********************************************
;DSP96001/2
;Matrix Multiply, [2x2] times [2x2]
;File name: 8-96
;**************************************************************************
;	Maximum execution time:  1.333 us at 27.0MHz
;	Memory Size: Prog: 18 words ; Data: 8 words (if a and c occupy the 
;                                                    same space)
;	Number of clock cycles:	  36 (18 instruction cycles)
;	Clock Frequency:	27.0 MHz
;	Cycle time:		74.1 ns
;**************************************************************************
;       This routine calculates a [2x2] times [2x2] matrix multiplication
;       for the DSP96000. Since modulo 4 addressing is used for all 
;       matrices, the first location must have the 2 lsb's =0.
;       All matrices are in "row major" format.
;
;       Matrix a is in X memory, 
;       matrix b is in Y memory,
;       matrix c is stored in X memory. 
;
;**************************************************************************
;     X Memory         Y Memory
;
; --->| a22 |      |--->| b22 |
; |   | a21 |    |-|--->| b21 |
; |   | a12 |    | |--->| b12 |
; --->| a11 |    |----->| b11 |
; r0              r4
;             
; --->| c22 |
; |   | c21 |
; |   | c12 |
; --->| c11 |
; r1
;
;The routine computes the result on a row-column basis, i.e. the
;row index changes fastest. The column pointer (r4) stays within
;the same column by using modulo addressing with offset. When
;all rows are calculated (r0 has wrapped around) column 2 is 
;chosen by simply decrementing r4, and repeating the same
;procedure
;
;Note: the previous assumes that all immediate addressing is
;immediate short, i.e. all data is in internal memory.
;
mata    equ     $100
matb    equ     $100
matc    equ     $200

        org     x:mata
        dc      $700000
        dc      $600000
        dc      $500000
        dc      $400000

        org     y:matb
        dc      $300000
        dc      $200000
        dc      $100000
        dc      $0F0000

        org     P:$40

;**************************************************************************
;
  move #mata, r0                                      ;r0 points to matrix a
  move #3,m0                                          ;address a modulo 4
  move #matb,r4                                       ;r4 points to matrix b
  move m0,m4                                          ;address b modulo 4
  move #matc,r1                                       ;r1 points to matrix c
  move #2,n4                                          ;offset is row length
  fmove                     x:(r0)+,d4   y:(r4)+n4,d5 ;load a11,b11
  fmpy d4,d5,d3             x:(r0)+,d4   y:(r4)+n4,d5 ;a11*b11
  fmpy d4,d5,d0             x:(r0)+,d4   y:(r4)+n4,d5 ;a12*b21
  fmpy d4,d5,d3 faddr d3,d0 x:(r0)+,d4   y:(r4)-,d5   ;a21*b11,a11*b11+a12*b21
  fmpy d4,d5,d1             x:(r0)+,d4   y:(r4)+n4,d5 ;a22*b21
  fmpy d4,d5,d3 faddr d3,d1 x:(r0)+,d4   y:(r4)+n4,d5 ;a11*b12,a21*b11+a22*b21
  fmpy d4,d5,d2             x:(r0)+,d4   y:(r4)+n4,d5 ;a12*b22
  fmpy d4,d5,d3 faddr d3,d2 x:(r0)+,d4   y:(r4)+,d5   ;a21*b12,a11*b12+a12*b22
  fmove                     d0,x:(r1)+                ;store c11
  fmpy d4,d5,d0             d2,x:(r1)+                ;a22*b22, store c12
                faddr d3,d0 d1,x:(r1)+                ;a21*b12+a22*b22,st.c21
  fmove                     d0,x:(r1)+                ;store c22
;**************************************************************************
  end

