title "fir4.asm" .mmregs .def start ;分配数据存储区 .bss y,1 ;y xn .usect "xn",80 ;xn h .usect "h",80 ;h PA0 .set 0000H ;数据输出端口 PA1 .set 0001H ;数据输入端口 ;参数表 .data table: .word -7,-18,-24,-22,-9,11,33,48 ;已在Matlab中转成十六进制的小数 .word 46,20,-24,-73,-104,-97,-43,49 .word 146,204,187,81,-91,-268,-371,-337 .word -144,162,476,661,603,261,-297,-894 .word -1283,-1222,-562,697,2373,4142,5618,6456 .word 6456,5618,4142,2373,697,-562,-1222,-1283 .word -894,-297,261,603,661,476,162,-144 .word -337,-371,-268,-91,81,187,204,146 .word 49,-43,-97,-104,-73,-24,20,46 .word 48,33,11,-9,-22,-24,-18,-7 start: SSBX FRCT ;小数乘法 ;把参数表复制到数据存储区 STM #h,AR1 RPT #79 MVPD #table,*AR1+ ;把x(n)-x(n-79)赋始值0 STM #xn,AR1 RPT #79 ST #0,*AR1+ STM #xn+79,AR3 ;x(n-79)---AR3 STM #h+79,AR4 ;h(n-79)---AR4 STM #80,BK ;循环缓冲区大小80 STM #-1,AR0 ;指针调整值-1 LD #xn,DP ;DP指向xn所在页 PORTR PA1,@xn ;输入数据 LD #y,DP ;DP指向y所在页 FIR: RPTZ A,#79 ;进行一次FIR运算 MAC *AR3+0%,*AR4+0%,A;A=(AR3)*(AR4)+A, AR3=AR3+AR0,AR4=AR4+AR0 STH A,@y ;保存计算结果 PORTW @y,PA0 ;输出结果 BD FIR ;读入下一个数据并进行下一次计算 PORTR PA1,*AR3+0% ;新数据覆盖了最旧的数据 .end |