home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / coding / dsp / c30ug.exe / $SUBR.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-04-11  |  2.2 KB  |  91 lines

  1. ;**************************************************************
  2. ;  
  3. ;                 $subr.asm
  4. ;  
  5. ;                 staff
  6. ;  
  7. ;                 04-11-88
  8. ;  
  9. ;           (C) Texas Instruments Inc., 1992 
  10. ;  
  11. ;           Refer to the file 'license.txt' included with this 
  12. ;           this package for usage and license information. 
  13. ;  
  14. ;**************************************************************
  15. Example 2.  Subroutine call (dot product)
  16. ;
  17. ;
  18.     .title    "Subroutine Call Example"
  19. ; Main routine that calls the subroutine DOT to compute the dot product
  20. ; of two vectors.
  21.       .
  22.       .
  23.       .
  24.       LDI        @blk0,AR0        ; AR0 points to vector a
  25.       LDI        @blk1,AR1        ; AR1 points to vector b
  26.       LDI        N,RC        ; RC contains the number of elements
  27.  
  28.       CALL        DOT
  29.       .
  30.       .
  31.       .
  32.  
  33.     .width 132
  34.     .text
  35. ;==============================================================================
  36. ;             SUBROUTINE    D O T
  37. ;
  38. ;
  39. ; EQUATION: d = a(0) * b(0) + a(1) * b(1) + ... + a(N-1) * b(N-1)
  40. ;
  41. ; The dot product of a and b is placed in register R0.    N must be greater than
  42. ; or equal to 2.
  43. ;
  44. ; ARGUMENT ASSIGNMENTS:
  45. ;   argument | function
  46. ;   ---------+-----------------------
  47. ;   AR0      | address of a(0)
  48. ;   AR1      | address of b(0)
  49. ;   RC         | length of vectors (N)
  50. ;
  51. ; REGISTERS USED AS INPUT: AR0, AR1, RC
  52. ; REGISTERS MODIFIED: R0, AR0, AR1, RC
  53. ; REGISTER CONTAINING RESULT: R0
  54. ;
  55. ;
  56. ;
  57.     .global     DOT
  58. ;
  59. DOT    PUSH    R2            ; use the stack to save R2's bottom 32
  60.     PUSHF    R2            ;    and top 32 bits
  61.     PUSH    ST            ; save status register
  62.     PUSH    AR0            ; save AR0
  63.     PUSH    AR1            ; save AR1
  64.     PUSH    RC            ; save RC
  65. ;                    ; initialize R0:
  66.     MPYF3    *AR0,*AR1,R0        ; a(0) * b(0) -> R0
  67.     LDF    0.0,R2            ; initialize R2.
  68.     SUBI    2,RC            ; set RC = N-2
  69. ;
  70. ; dot product (1 <= i < N)
  71. ;
  72.         RPTS    RC                      ; setup the repeat single.
  73.     MPYF3    *++AR0(1),*++AR1(1),R0    ; a(i) * b(i) -> R0
  74. ||    ADDF3    R0,R2,R2        ; a(i-1)*b(i-1) + R2 -> R2
  75. ;
  76.     ADDF3    R0,R2,R0        ; a(N-1)*b(N-1) + R2 -> R0
  77. ;
  78. ; return sequence
  79. ;
  80.     POP    RC            ; restore RC
  81.     POP    AR1            ; restore AR1
  82.     POP    AR0            ; restore AR0
  83.     POP    ST            ; restore ST
  84.     POPF    R2            ; restore top 32 bits of R2
  85.     POP    R2            ; restore bottom 32 bits of R2
  86.         RETS                            ; return
  87. ;
  88. ; end
  89. ;
  90.     .end
  91.