⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex7p8mat.asm

📁 用于DSK5416的程序
💻 ASM
字号:
;___________________________________________________________________________
;
; Program Name: ex7p8MAT.asm
;
; Description:  This is an example to show how to implement matrix mutiplication.
;               It implements the following equation
;
;               C = A.B
;
;               where
;               A is a 3 x 4 matrix,
;               B is a 4 x 3 matrix, and
;               C is a 3 x 3 matrix
;
;               Matrix A elements are stored in data memory row after row.
;               Matrix B elements are stored in data memory column after column.
;               Matrix C elements are stored in data memory row after row.
;
;               All elements are q15 numbers.
;		
; Author:       Avtar Singh, SJSU
;
;___________________________________________________________________________



                .mmregs                         ;memory-mapped registers

                .ref    _c_int00

                .sect   ".vectors"

RESET:          B _c_int00                      ;Reset vector
                NOP
                NOP


                .data

matArow1:       .word 1000h,2000h,3000h,4000h   ;row 1 of matrix A
matArow2:       .word 1000h,2000h,3000h,4000h   ;row 2 of matrix A
matArow3:       .word 1000h,2000h,3000h,4000h   ;row 3 of matrix A

matBcol1:       .word 1000h,2000h,3000h,4000h   ;column 1 of matrix B
matBcol2:       .word 1000h,2000h,3000h,4000h   ;column 2 of matrix B
matBcol3:       .word 1000h,2000h,3000h,4000h   ;column 3 of matrix B

matC:           .word 0,0,0                     ;row 1 of matrix C
                .word 0,0,0                     ;row 2 of matrix C
                .word 0,0,0                     ;row 3 of matrix C

Nm1             .set 3                          ;columns of matrix A - 1


                .text

_c_int00:
                ssbx sxm                       ;select sign extension mode
                stm #matC, ar3                 ;ar3 = matrix C start address
                stm #matArow1, ar1             ;ar1 = matrix A row 1 start address
                stm #matBcol1, ar2             ;ar2 = matrix B col 1 start address
                stm #Nm1, BRC                  ;BRC = row/col elements - 1
                call DOTPROD                   ;find dot product
                sth a,1,*ar3+                  ;save the result as matrix C element

                stm #matArow1, ar1             ;ar1 = matrix A row 1 start address
                stm #matBcol2, ar2             ;ar2 = matrix B col 2 start address
                stm #Nm1, BRC                  ;BRC = row/col elements - 1
                call DOTPROD                   ;find dot product
                sth a,1,*ar3+                  ;save the result as matrix C element

                stm #matArow1, ar1             ;ar1 = matrix A row 1 start address
                stm #matBcol3, ar2             ;ar2 = matrix B col 3 start address
                stm #Nm1, BRC                  ;BRC = row/col elements - 1
                call DOTPROD                   ;find dot product
                sth a,1,*ar3+                  ;save the result as matrix C element

                stm #matArow2, ar1             ;ar1 = matrix A row 2 start address
                stm #matBcol1, ar2             ;ar2 = matrix B col 1 start address
                stm #Nm1, BRC                  ;BRC = row/col elements - 1
                call DOTPROD                   ;find dot product
                sth a,1,*ar3+                  ;save the result as matrix C element

                stm #matArow2, ar1             ;ar1 = matrix A row 2 start address
                stm #matBcol2, ar2             ;ar2 = matrix B col 2 start address
                stm #Nm1, BRC                  ;BRC = row/col elements - 1
                call DOTPROD                   ;find dot product
                sth a,1,*ar3+                  ;save the result as matrix C element

                stm #matArow2, ar1             ;ar1 = matrix A row 2 start address
                stm #matBcol3, ar2             ;ar2 = matrix B col 3 start address
                stm #Nm1, BRC                  ;BRC = row/col elements - 1
                call DOTPROD                   ;find dot product
                sth a,1,*ar3+                  ;save the result as matrix C element

                stm #matArow3, ar1             ;ar1 = matrix A row 3 start address
                stm #matBcol1, ar2             ;ar2 = matrix B col 1 start address
                stm #Nm1, BRC                  ;BRC = row/col elements - 1
                call DOTPROD                   ;find dot product
                sth a,1,*ar3+                  ;save the result as matrix C element

                stm #matArow3, ar1             ;ar1 = matrix A row 3 start address
                stm #matBcol2, ar2             ;ar2 = matrix B col 2 start address
                stm #Nm1, BRC                  ;BRC = row/col elements - 1
                call DOTPROD                   ;find dot product
                sth a,1,*ar3+                  ;save the result as matrix C element

                stm #matArow3, ar1             ;ar1 = matrix A row 3 start address
                stm #matBcol3, ar2             ;ar2 = matrix B col 3 start address
                stm #Nm1, BRC                  ;BRC = row/col elements - 1
                call DOTPROD                   ;find dot product
                sth a,1,*ar3+                  ;save the result as matrix C element
                nop
                nop
                nop

;----------------------------------------------------------------------
;
;       Dot Product Routine
;
;       This routine determines the dot product of two vectors
;
;       Input:  ar1 = pointer to the first element of vector 1
;               ar2 = pointer to the first element of vector 2
;               BRC = size - 1 for either vector
;
;               All elements are q15 numbers
;
;       Output: A = dot product as q30 number
;
;-----------------------------------------------------------------------

DOTPROD:
                ld #0, a                        ;A = 0
NXTeleofA:
                rptb end_dotp-1                 ;A = sum of ar1(i)*ar2(i) for all i
                ld *ar2+, t
                mac *ar1+, a
end_dotp:       ret                             ;return
                nop
                nop
				
                .end


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -