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

📄 fft32.asm

📁 本光盘为《TMS320X240xDSP原理及应用开发指南》一书随书光盘。 本光盘包含两部分内容: 1. 《TMS320X240x DSP原理及应用开发指南》一书的前言; 2. 《TMS320X2
💻 ASM
📖 第 1 页 / 共 3 页
字号:
brev1LP1:   LACC    *,16,AR4        ; ARP=AR4, AR4=dst, ACCH=*src
            ADDS    *,AR5           ; ARP=AR5, AR5->temp, ACCL=*dst
            SAR     AR4,*           ; ARP=AR5, AR5->temp, temp=dst   
            LAR     AR0,*-,AR3      ; ARP=AR3, AR3=src, AR5=FP, AR0=dst 
            CMPR    1               ; check AR3<AR0
            BCND    noswap,NTC      ; if src<dst, do not swap *src & *dst
            SACL    *,AR4           ; ARP=AR4, AR4=dst, *src=*dst
            SACH    *,AR3           ; ARP=AR3, AR3=src, *dst=*src
           
noswap:     MAR     *+,AR5          ; ARP=AR5, AR5=FP, (FP)=size/2, AR3=src+1
            LAR     AR0,*+,AR3      ; ARP=AR3, AR3=src+1, AR0=size/2, AR5->temp 
            MAR     *+,AR4          ; ARP=AR4, AR4=dst, AR3=src+2
            MAR     *BR0+,AR7       ; ARP=AR7, AR7=(size/2)-1, dst=br(dst+size/2)
            BANZ    brev1LP1,*-,AR3 ; ARP=AR3, AR3->src+2, AR7=AR7-1 
             
            MAR     *,AR2           ; ARP=AR2, AR2->dst
            LAR     AR3,*,AR5       ; ARP=AR5, AR5->temp, AR3=dst=src   
            SBRK    #1              ; ARP=AR5, AR5=FP, (FP)=size/2
            LACC    *+,1,AR2        ; ARP=AR2, AR2->dst, AR5->temp, ACCL=size
            ADDS    *,AR5           ; ARP=AR5, AR5->temp, ACCL=dst+size 
            SACL    *               ; ARP=AR5, AR5->temp, temp=dst+size
            LAR     AR4,*-          ; ARP=AR5, AR5=FP, AR4=dst+size
            LAR     AR0,*           ; ARP=AR5, AR5=FP, (FP)=size/2, AR0=size/2
            LAR     AR7,*,AR7       ; ARP=AR7, AR7=size/2
            MAR     *-,AR3          ; ARP=AR3, AR3=src, AR7=(size/2)-1 
            ADRK    #1              ; ARP=AR3, AR3=src+1
                    
brev1LP2:   LACL    *+              ; ARP=AR3, AR3=src+2, ACCL=*(src+1)
            MAR     *+,AR4          ; ARP=AR4, AR4=dst+size, AR3=src+3
            SACL    *BR0+,0,AR7     ; ARP=AR7, AR7=(size/2)-1, AR4=br(dst+size+size/2)
            BANZ    brev1LP2,*-,AR3  ; ARP=AR3, AR3=src+3, AR7=AR7-1
                        
            MAR     *,AR1
            SBRK    #(__FFTC_brev1_frs+1) ; Clear the local frame
            LAR     AR7,*-
            LAR     AR0,*-          ; Retrive Caller's frame pointer
            PSHD    *               ; Push the return address to TOS
            RET  

OFFBREV:    MAR     *,AR2           ; ARP=AR2, AR2->size
            LAR     AR0,*           ; ARP=AR2, AR2->size, AR0=size      
            LAR     AR7,*,AR7       ; ARP=AR7, AR7=size
            MAR     *-,AR3          ; ARP=AR3, AR3=src, AR7=size-1
            
offbrevLP   LACL    *+,AR4          ; ARP=AR4, AR4=dst, AR3=src+1, ACCL=*src
            SACL    *BR0+,0,AR7     ; ARP=AR7, AR7=size-1, AR4=br(dst+size)
            BANZ    offbrevLP,*-,AR3 ; ARP=AR3, AR3->src+1, AR7=AR7-1                  
            
            MAR     *,AR1
            SBRK    #(__FFTC_brev1_frs+1)   ; Clear the local frame
            LAR     AR7,*-
            LAR     AR0,*-          ; Retrive Caller's frame pointer
            PSHD    *               ; Push the return address to TOS
            RET  

;第四个函数
;============================================================================
; File Name     : cfft_izc.asm
;===========================================================================    
__FFTC_izero_frs    .set   00001h       ; Local frame size for this routine 
                .def   _FFTC_izero  ;
            
_FFTC_izero: 
            POPD    *+              ; Store the Return Address in stack
            SAR     AR0,*+          ; Store the Caller's Frame Pointer
            SAR     AR1,*                 
            LAR     AR2,*
            LAR     AR0,#__FFTC_izero_frs       
            LAR     AR4,*0+,AR2     ; Create Local frame
            
            SBRK    #3              ; ARP=AR2, AR2=FP-3->FFTxxxC_handle
            LAR     AR2,*           ; ARP=AR2, AR2=FFTxxxC_handle->ipcbptr
            
; Fill the imaginary part of the samples with ZERO 
            LAR     AR3,*,AR3       ; ARP=AR3, AR3=ipcbptr
            MAR     *+,AR2          ; ARP=AR2, AR2->ipcbptr, AR3=ipcbptr+1
            ADRK    #5              ; ARP=AR2, AR2->size 
            LACL    *,AR4           ; ARP=AR4, AR4=FP, ACCL=size
            SUB     #1              ; ARP=AR4, AR4=FP, ACCL=size-1
            SACL    *               ; ARP=AR4, AR4=FP, (FP)=size-1
            LAR     AR0,#2          ; ARP=AR4, AR4=FP, AR0=2
            LACL    #0
            RPT     *,AR3
            SACL    *0+             
                            
            MAR     *,AR1
            SBRK    #(__FFTC_izero_frs+1)   ; Clear the local frame
            LAR     AR0,*-          ; Retrive Caller's frame pointer
            PSHD    *               ; Push the return address to TOS
            RET 
;第五个函数
;============================================================================
; File Name     : cfft_magc.asm
;===========================================================================    
MAGQFMT         .set   14           ; Magnitude Q Format (15 or 14)                                           
__FFT_mag_frs   .set   00001h       ; Local frame size for this routine 
                .def   _FFTC_mag    ;
            
_FFTC_mag: 
            POPD    *+              ; Store the Return Address in stack
            SAR     AR0,*+          ; Store the Caller's Frame Pointer
            SAR     AR1,*                 
            LAR     AR0,#__FFT_mag_frs      
            LAR     AR0,*0+,AR2     ; Create Local frame
            
            SETC    SXM
            SPM     #0
            
            LAR     AR2,#0FFFDh     ; ARP=AR2, AR2=-3
            MAR     *0+             ; ARP=AR2, AR2=FP-3->FFTxxxC_handle
            LAR     AR2,*           ; ARP=AR2, AR2=FFTxxxC_handle->ipcbptr
            LAR     AR4,*+          ; ARP=AR2, AR2->magptr, AR4=ipcbptr
            LAR     AR3,*           ; ARP=AR2, AR2->magptr, AR3=magptr
            ADRK    #4h             ; ARP=AR2, AR2->size
            LAR     AR5,*           ; ARP=AR2, AR2->size, AR5=size
            SBRK    #4h             ; ARP=AR2, AR2->magptr
            MAR     *,AR5           ; ARP=AR5, AR5=size
            MAR     *-,AR4          ; ARP=AR4, AR4=ipcbptr, AR5=size-1
        
MAG_LP:     LACC    #0000           ; Clear ACC
            MPY     #0              ; Clear PREG
            SQRA    *+              ; Q15*Q15=Q30
            SQRA    *+,AR3          ; Q15*Q15+Q30=Q30
            APAC                    ; Q15*Q15+Q30=Q30
            SACH    *+,(MAGQFMT-14),AR5        ; Store in MAGQFMT
            BANZ    MAG_LP,*-,AR4
           
;---------------------------------------------------------------------------------------------
; The results from FFT may be very small, if the signal power is less. As a result, the
; magnitudes of the FFT are normalised so that the maximum magnitude is represented as 0x7fffh
;---------------------------------------------------------------------------------------------
            MAR     *,AR2           ; ARP=AR2, AR2->magptr 
            LAR     AR3,*+          ; ARP=AR2, AR2->peakmag, AR3=magptr
            SPLK    #0000h,*        ; ARP=AR2, AR2->peakmag, peakmag=0
            ADRK    #3              ; ARP=AR2, AR2->size
            LAR     AR5,*           ; ARP=AR2, AR2->size, AR5=size
            SBRK    #3              ; ARP=AR2, AR2->peakmag
            MAR     *,AR5           ; ARP=AR5, AR5=size
            MAR     *-,AR3          ; ARP=AR3, AR3=magptr, AR5=size-1
            LAR     AR4,#0FFFFh     ; ARP=AR3, AR3=magptr, AR4=FFFF
;Following section finds the maximum value among the FFT Magnitudes

FINDMAX:    LACC    *+,0,AR2
            SUB     *,AR4           
            MAR     *+,AR5          
            BCND    NEXTCMP,LEQ     ;
            MAR     *,AR2           ; ARP=AR2, AR2->peakmag
            ADD     *               ; ARP=AR2, AR2->peakmag 
            SACL    *+              ; ARP=AR2, AR2->peakfrq
            SAR     AR4,*-,AR5      ; ARP=AR5, AR2->peakmag
NEXTCMP:    BANZ    FINDMAX,*-,AR3
            
            MAR     *,AR2           ; ARP=AR2, AR2->peakmag
            ADRK    #2              ; ARP=AR2, AR2->normflag
            
            LACL    *+              ; ARP=AR2, AR2->size, ACCL=normflag
            BCND    SKIPNORM,EQ     ; Check normflag==0?

;Following Section normalizes the FFT amplitudes

             LAR    AR5,*           ; ARP=AR2, AR2->size, AR5=size
             SBRK   #4              ; ARP=AR2, AR2->magptr
             LAR    AR3,*+,AR5      ; ARP=AR5, AR5=size, AR3=magptr, AR2->peakmag
             MAR    *-,AR3          ; ARP=AR3, AR3=magptr, AR5=size-1
             
                    
NEXTNORM:    LACC   *,15,AR2        ; ARP=AR2, AR2->peakmag
             RPT    #15
             SUBC   * 
             MAR    *,AR3
             SACL   *+,0,AR5    
             BANZ   NEXTNORM,*-,AR3 

;The following section corrects the value obtained when the maximum value is divided 
;by itself. change 8000h to max Q15 value of 7fffh
            
            MAR     *,AR2           ; ARP=AR2, AR2->peakmag
            SBRK    #1              ; ARP=AR2, AR2->magptr
            LAR     AR3,*           ; ARP=AR2, AR2->magptr, AR3=magptr
            ADRK    #4              ; ARP=AR2, AR2->size
            LAR     AR5,*,AR5       ; ARP=AR5, AR5=size
            MAR     *-,AR3          ; ARP=AR3, AR3=magptr, AR5=size-1

NEXTVAL:    LACC    *               
            SUB     #8000h 
            BCND    POSSAT,NEQ
            LACC    #0FFFFh
POSSAT:     ADD     #8000h
            SACL    *+,0,AR5
            BANZ    NEXTVAL,*-,AR3
            
SKIPNORM:   MAR     *,AR1
            SBRK    #(__FFT_mag_frs+1)  ; Clear the local frame
            LAR     AR0,*-          ; Retrive Caller's frame pointer
            PSHD    *               ; Push the return address to TOS
            RET      

;--------------------------------------------------------------------------
; TWIDDLE FOR N=32 FFT (24 ENTRIES)
;--------------------------------------------------------------------------     
        .sect   "FFTtf" 
        .label  TF_LOAD_STRT_ADR                    
TWID:   .word   0,6393,12540,18205,23170,27246,30274,32138,32767,32138
        .word   30274,27246,23170,18205,12540,6393,0,-6393,-12540,-18205
        .word   -23170,-27246,-30274,-32138
        .label  TF_LOAD_END_ADR
          

⌨️ 快捷键说明

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