TI TMS320vc5416下的sine值汇编代码

;****************C****O****D****E*********************************
    .mmregs
;=======================CONSTANTS================================+
X05_Q15 .set    16384                   ; (.5 * (1 << 15))
ONE_Q15 .set    32767                   ; ((1 << 15) -1)
    .data
;=======================PARAMETERS===============================+
;*                                                               *
;*  Name    :   _sineTable                                       *
;*  Type    :   signed 16 bits integer array                     *
;*  Length  :   129units                                         *
;*  Size    :   129*(16/16)words                                 *
;*  Cost    :   129 words                                        *
;*  Usage   :   fraction part sine looking-up.                   *
;*  Note    :   DO NOT MODIFY THESE DATAS!!                      *
;*                                                               *
;================================================================+
_sineTable
    .word   0,   402,   804,  1206,  1608,  2009,  2411,  2811,  3212
    .word   3612,  4011,  4410,  4808,  5205,  5602,  5998,  6393,  6787
    .word   7180,  7571,  7962,  8351,  8740,  9127,  9512,  9896, 10279
    .word   10660, 11039, 11417, 11793, 12167, 12540, 12910, 13279, 13646
    .word   14010, 14373, 14733, 15091, 15447, 15800, 16151, 16500, 16846
    .word   17190, 17531, 17869, 18205, 18538, 18868, 19195, 19520, 19841
    .word   20160, 20475, 20788, 21097, 21403, 21706, 22006, 22302, 22595
    .word   22884, 23170, 23453, 23732, 24008, 24279, 24548, 24812, 25073
    .word   25330, 25583, 25833, 26078, 26320, 26557, 26791, 27020, 27246
    .word   27467, 27684, 27897, 28106, 28311, 28511, 28707, 28899, 29086
    .word   29269, 29448, 29622, 29792, 29957, 30118, 30274, 30425, 30572
    .word   30715, 30853, 30986, 31114, 31238, 31357, 31471, 31581, 31686
    .word   31786, 31881, 31972, 32058, 32138, 32214, 32286, 32352, 32413
    .word   32470, 32522, 32568, 32610, 32647, 32679, 32706, 32729, 32746
    .word   32758, 32766, 32767
;=======================FUNCTIONS================================+
;*                                                               *
;*  Name    :   _sine                                            *
;*  Argument:                                                    *
;*              x   INT16S  Q15 16bits signed integer            *
;*              return  INT16S  Q15 sine(x)                      *
;*  Invoked :                                                    *
;*              C-style                                          *
;*                      y=sine(x);                               *
;*              asm-style                                        *
;*                      x->A                                     *
;*                      CALL    _sine                            *
;*  Contents:                                                    *
;*              Compute the sine of x whose value is expressed   *
;*              in radians/PI.                                   *
;*              You can get cosine(x) with this function easily, *
;*              cause of cos(x)=sin(PI/2-x). In C file,you can   *
;*              just use #define cosine(x) sine(16384-x).Where   *
;*              16384 is 0.5(stands for PI/2)'s Q15 value.       *
;*  Notes   :   none                                             *
;*                                                               *
;================================================================+
    .sect    ".text"                   
    .global    _sine                   
    .global _sineTable                  ; for other program usage
sign    .set    1                      
index   .set    2                      
_sine:                                 
        PSHM      AR1                  
        FRAME     #-3                  
        SSBX      SXM                  
        SSBX      OVM                  
        SSBX      FRCT                 
        ST        #1,*SP(sign)         
        LD        A,0,B                
        BC        POSITIVE,AGT         
        ST        #-1,*SP(sign)        
        NEG       B                    
POSITIVE:                              
        SUB       #X05_Q15,B,A         
        BC        LTPI_2,ALEQ          
        LD        #ONE_Q15,A           
        SUB       B,A                  
        LD        A,B                  
LTPI_2:                                
        STL       B,-7,*SP(index)      
        LD        #_sineTable,A        
        ADD       *SP(index),A         
        STLM      A,AR1                
        CMPM      *SP(index),#128      
        BC        LOOP_UP,NTC          
        LD        *AR1,B               
        B         CHECK_SIGN           
LOOP_UP:                               
        SUB       *SP(index),7,B       
        LD        B,8,B                
        LD        *AR1(1),16,A         
        SUB       *AR1,16,A            
        LD        *(BL),T              
        MPYA      A                    
        ADD       *AR1,16,A            
        LD        A,-16,B              
CHECK_SIGN:                            
        LD        *SP(sign),A          
        BC        EXIT,AGT             
        NEG       B                    
EXIT:                                  
        LD        B,A                  
        FRAME     #3                   
        POPM      AR1                  
        RET                             ; return INT16S
        .end                           
 
两年前写的代码,给有需要的人

本文出自 “神木小子” 博客,转载请与作者联系!

你可能感兴趣的:(职场,休闲,dsp)