home *** CD-ROM | disk | FTP | other *** search
- ;**************************************************************
- ;
- ; $subr.asm
- ;
- ; staff
- ;
- ; 04-11-88
- ;
- ; (C) Texas Instruments Inc., 1992
- ;
- ; Refer to the file 'license.txt' included with this
- ; this package for usage and license information.
- ;
- ;**************************************************************
- Example 2. Subroutine call (dot product)
- ;
- ;
- .title "Subroutine Call Example"
- ; Main routine that calls the subroutine DOT to compute the dot product
- ; of two vectors.
- .
- .
- .
- LDI @blk0,AR0 ; AR0 points to vector a
- LDI @blk1,AR1 ; AR1 points to vector b
- LDI N,RC ; RC contains the number of elements
-
- CALL DOT
- .
- .
- .
-
- .width 132
- .text
- ;==============================================================================
- ; SUBROUTINE D O T
- ;
- ;
- ; EQUATION: d = a(0) * b(0) + a(1) * b(1) + ... + a(N-1) * b(N-1)
- ;
- ; The dot product of a and b is placed in register R0. N must be greater than
- ; or equal to 2.
- ;
- ; ARGUMENT ASSIGNMENTS:
- ; argument | function
- ; ---------+-----------------------
- ; AR0 | address of a(0)
- ; AR1 | address of b(0)
- ; RC | length of vectors (N)
- ;
- ; REGISTERS USED AS INPUT: AR0, AR1, RC
- ; REGISTERS MODIFIED: R0, AR0, AR1, RC
- ; REGISTER CONTAINING RESULT: R0
- ;
- ;
- ;
- .global DOT
- ;
- DOT PUSH R2 ; use the stack to save R2's bottom 32
- PUSHF R2 ; and top 32 bits
- PUSH ST ; save status register
- PUSH AR0 ; save AR0
- PUSH AR1 ; save AR1
- PUSH RC ; save RC
- ; ; initialize R0:
- MPYF3 *AR0,*AR1,R0 ; a(0) * b(0) -> R0
- LDF 0.0,R2 ; initialize R2.
- SUBI 2,RC ; set RC = N-2
- ;
- ; dot product (1 <= i < N)
- ;
- RPTS RC ; setup the repeat single.
- MPYF3 *++AR0(1),*++AR1(1),R0 ; a(i) * b(i) -> R0
- || ADDF3 R0,R2,R2 ; a(i-1)*b(i-1) + R2 -> R2
- ;
- ADDF3 R0,R2,R0 ; a(N-1)*b(N-1) + R2 -> R0
- ;
- ; return sequence
- ;
- POP RC ; restore RC
- POP AR1 ; restore AR1
- POP AR0 ; restore AR0
- POP ST ; restore ST
- POPF R2 ; restore top 32 bits of R2
- POP R2 ; restore bottom 32 bits of R2
- RETS ; return
- ;
- ; end
- ;
- .end