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

📄 fir_filters_asm.asm

📁 TI CCS开发环境下的FIR滤波器实现工程
💻 ASM
字号:
;******************************************************************************
;* FILENAME                                                                   *
;*   FIR_filters_asm.asm                                                      *
;*                                                                            *
;* DESCRIPTION                                                                *
;*   Finite Impulse Response Filters using the TMS320C5416 DSK.               *
;*   Implemented in assembly language because C code versions are too slow    *
;*                                                                            *
;*  Revision: 1.00                                                            *
;*  Author: Richard Sikora                                                    *
;*                                                                            *
;*----------------------------------------------------------------------------*
;*  HISTORY                                                                   *
;*  Revision: 1.00                                                            *
;*  11th November 2002. Created by Richard Sikora from FIR_filters.c          *
;*                                                                            *
;*----------------------------------------------------------------------------*
;*                                                                            *
;*  The number of FIR filter elements is controlled by N                      *
;*                                                                            * 
;******************************************************************************

	.mmregs
FP	.set	AR7
N   .set    51             

	.sect	".text"

; First buffer of N = 51 elements  

	.bss	_buffer1,51,0,0

; Second buffer of N = 51 elements  

    .bss    _buffer2,N,0,0

; Third buffer of N = 51 elements  

    .bss    _buffer3,N,0,0
    
; Fourth buffer of N = 51 elements  

    .bss    _buffer4,N,0,0    

; Give functions global scope to make them available to other functions

	.sect	".text"
	
	.global _FIR_filters_asm_initialize

	.global _FIR_dual_filter_asm                  
    
;******************************************************************************
;* FUNCTION DEF: _FIR_asm_initialize                                          *
;******************************************************************************
;*                                                                            *
;* Fill four buffers used for FIR filters with zeroes to prevent noise and    *
;* clicks.                                                                    *
;*                                                                            *
;******************************************************************************

_FIR_filters_asm_initialize:
 
       PSHM       AR3              ; Temporary save AR3
       
       STM        #_buffer1, AR3   ; AR3 points to buffer1[0]

       RPT        #(N-1)           ; N - 1 repeats
       ST         #0, *AR3+        ; Fill each element with zero

       STM        #_buffer2, AR3   ; AR3 points to buffer2[0]

       RPT        #(N-1)           ; N - 1 repeats
       ST         #0, *AR3+        ; Fill each element with zero

       STM        #_buffer3, AR3   ; AR3 points to buffer3[0]

       RPT        #(N-1)           ; N - 1 repeats
       ST         #0, *AR3+        ; Fill each element with zero
       
       STM        #_buffer4, AR3   ; AR3 points to buffer4[0]

       RPT        #(N-1)           ; N - 1 repeats
       ST         #0, *AR3+        ; Fill each element with zero       
       
       POPM       AR3              ; Restore AR3
       
       FRET                        ; Far return 


;******************************************************************************
;* FUNCTION DEF: _FIR_dual_filter_asm                                         *
;******************************************************************************
;*                                                                            *
;* FIR filter for producing both high pass and low pass filter from a single  *
;* set of coefficients.                                                       *
;*                                                                            *
;* Bass and treble returned in AH and AL                                      *
;*                                                                            *
;******************************************************************************

_FIR_dual_filter_asm:

	    PSHM      ST0                   ; Keep original values of flags
	    PSHM      ST1
        PSHM      AR3                   ; Keep original values of registers
        PSHM      AR4
        
        SSBX      OVM                   ; Prevent overflow 
        SSBX      FRCT                  ; Shift right to remove extra sign bit 
        SSBX      SXM                   ; Turn on sign-extension mode
        
        FRAME     #-1
        STLM      A, AR3                ; AR3 now points to _coefficients

; Start by shuffling values in buffer along and inserting new value at buffer3[0]

        STM       #_buffer3+N-2, AR4    ; AR4 points to buffer3[49]                 
	    RPT       #(N-2)                ; Shuffle all the values. # is important!
	    DELAY     *AR4-

        MVDK      *SP(4+3), *(_buffer3)  ; New input to beginning of buffer  
        STM       #_buffer3, AR4         ; AR4 now points to buffer3[0]

; Series of multiplications with accumulation. Last with rounding.  

        RPTZ      A, #(N-2)              ; Clear A then repeat 49 times
        MAC       *AR3+, *AR4+, A        ; Multiply and accumulate in A  
         
        MACR      *AR3+, *AR4+, A        ; Round up the last one. This makes AL = 0.                                    

        SFTA      A, -16, B              ; Remove fractional part of product and copy 
                                         ; to accumulator B. AH also contains product.  
        NEG       B                      ; product = -product  

        STM       #_buffer3+(N-1)/2, AR4 ; AR4 points to mid point i.e. buffer3[25] 

        ADD       *AR4, 0, B, B          ; Mid point + (- product)
                                         ; If AH contains bass, BL contains treble.
        
        AND       #0FFFFh, B             ; Ensure BH is zero.

        OR        B, 0, A                ; Return A OR B in Accumulator A

        FRAME     #1 
        
        POPM      AR4                    ; Restore registers  
        POPM      AR3
        POPM      ST1                    ; Restore flags
        POPM      ST0                    

        FRET                             ; Far return                                
      

;******************************************************************************
;* End of FIR_filters_asm.asm                                                 *
;******************************************************************************

⌨️ 快捷键说明

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