我已经为 CCS V5 中的 FIR 实现编写了这段代码。
调试时
LDH .D1 *A4,A2 ; A2=x[n-k] k=1,...,N
LDH .D2 *B4++,B2 ; B2=h[k] k=1,...,N
这部分代码被忽略,或者说 A2 和 B2 的值保持不变。我尝试将 const 值数组赋予参数,但没有帮助。我猜它的浮点格式有一些问题。
任何帮助表示赞赏。
#include<stdio.h>
#include<stdlib.h>
#define N 4
extern FIR_asm_func();
int main()
{
int y;//,h;
float out;
float x[N+1]={20,0,0,0,0};
FILE *fip,*fop;
char signal[]="signal";
char output[]="output";
float coeff[]={1,1,1,1,1};
fip = fopen('signal',"r"); // read mode
fop = fopen('output',"w"); // write mode
y=201;
while(y--)
{
fscanf(fip,"%f",&x[0]);
//printf("%d\n",x[0]);
out = FIR_asm_func(x,coeff,5);
fprintf(fop,"%f,",out);
}
fclose(fip);
fclose(fop);
printf("End");
return 0;
}
; FIR_asm_func.asm
; asm function called from C to implement fixed-point FIR
; A4 = x[n] address, B4 = h[0] address, A6 = filter order N
; input samples organized as x(n)...x(n-N)
; coefficients as h[0]...h[N]
.global _FIR_asm_func
_FIR_asm_func:
MV .L1 A6,A1 ; setup loop count in A1
ZERO .S1 A8 ; initialization A8 for accumulation
LDH .D1 *A4++,A2 ; x[n]
LDH .D2 *B4++,B2 ; h[0]
MPY .M1 A2,B2,A7 ; A7=x[n]*h[0]
ADD .L1 A7,A8,A8 ; accumlate in A8
LOOP:
MV .L1 A2,A3 ; making space for newer sample
LDH .D1 *A4,A2 ; A2=x[n-k] k=1,...,N
LDH .D2 *B4++,B2 ; B2=h[k] k=1,...,N
STH .D1 A3,*A4++ ;
MPY .M1 A2,B2,A7 ; A7=h[k]*x[n-k]
ADD .L1 A7,A8,A8 ; accumulate in A8
SUB .S1 A1,1,A1 ; decrement loop count A1
[A1] B .S2 LOOP ; branch to loop if A1 # 0
NOP
MV .L1 A8,A4 ; result returned in A4
B .S2 B3 ; return addr to calling routine
NOP
.end