www.pudn.com > fft_iccavr.rar > ff.s
.module ff.c .area data(ram, con, rel) _dataR:: .blkb 4 .area idata .word 0x0,0x40a0 .area data(ram, con, rel) .blkb 4 .area idata .word 0x0,0x40a0 .area data(ram, con, rel) .blkb 4 .area idata .word 0x0,0x40a0 .area data(ram, con, rel) .blkb 4 .area idata .word 0x0,0x40a0 .area data(ram, con, rel) .blkb 4 .area idata .word 0x0,0x0 .area data(ram, con, rel) .blkb 4 .area idata .word 0x0,0x0 .area data(ram, con, rel) .blkb 4 .area idata .word 0x0,0x0 .area data(ram, con, rel) .blkb 4 .area idata .word 0x0,0x0 .area data(ram, con, rel) .dbfile D:\HJN\Design\AVR\fft\ff.c .dbsym e dataR _dataR A[32:8]D _dataI:: .blkb 4 .area idata .word 0x0,0x0 .area data(ram, con, rel) .dbfile D:\HJN\Design\AVR\fft\ff.c .blkb 4 .area idata .word 0x0,0x0 .area data(ram, con, rel) .dbfile D:\HJN\Design\AVR\fft\ff.c .blkb 4 .area idata .word 0x0,0x0 .area data(ram, con, rel) .dbfile D:\HJN\Design\AVR\fft\ff.c .blkb 4 .area idata .word 0x0,0x0 .area data(ram, con, rel) .dbfile D:\HJN\Design\AVR\fft\ff.c .blkb 4 .area idata .word 0x0,0x0 .area data(ram, con, rel) .dbfile D:\HJN\Design\AVR\fft\ff.c .blkb 4 .area idata .word 0x0,0x0 .area data(ram, con, rel) .dbfile D:\HJN\Design\AVR\fft\ff.c .blkb 4 .area idata .word 0x0,0x0 .area data(ram, con, rel) .dbfile D:\HJN\Design\AVR\fft\ff.c .blkb 4 .area idata .word 0x0,0x0 .area data(ram, con, rel) .dbfile D:\HJN\Design\AVR\fft\ff.c .dbsym e dataI _dataI A[32:8]D .area text(rom, con, rel) .dbfile D:\HJN\Design\AVR\fft\ff.c .dbfunc e FFT _FFT fV ; xx -> y+12 ; x2 -> R14,R15 ; x1 -> R10,R11 ; x0 -> R12,R13 ; L -> y+24 ; j -> R10,R11 ; temp -> y+8 ; TI -> y+4 ; TR -> y+0 ; b -> y+22 ; p -> R14,R15 ; k -> R12,R13 ; dataI -> y+38 ; dataR -> y+36 .even _FFT:: xcall push_arg4 xcall push_gset5 sbiw R28,26 .dbline -1 .dbline 10 ; #include; #include ; #define PI 3.1415926 ; ; unsigned char i,w[32]; ; float dataR[]={5,5,5,5,0,0,0,0}; ; float dataI[]={0,0,0,0,0,0,0,0}; ; ; void FFT(float dataR[],float dataI[]) ; { .dbline 17 ; int x0,x1,x2,xx; ; ; int L,j,k,b,p; ; float TR,TI,temp; ; ; /********** following code invert sequence ************/ ; for(i=0;i<8;i++) clr R2 sts _i,R2 xjmp L5 L2: .dbline 18 .dbline 19 clr R14 clr R15 clr R10 clr R11 clr R12 clr R13 .dbline 20 lds R24,_i clr R25 andi R24,1 andi R25,0 movw R12,R24 .dbline 21 ldi R18,2 ldi R19,0 lds R16,_i clr R17 xcall div16s movw R24,R16 andi R24,1 andi R25,0 movw R10,R24 .dbline 22 ldi R18,4 ldi R19,0 lds R16,_i clr R17 xcall div16s movw R24,R16 andi R24,1 andi R25,0 movw R14,R24 .dbline 23 ldi R16,2 ldi R17,0 movw R18,R10 xcall empy16s movw R2,R16 ldi R16,4 ldi R17,0 movw R18,R12 xcall empy16s movw R4,R16 add R4,R2 adc R5,R3 add R4,R14 adc R5,R15 std y+13,R5 std y+12,R4 .dbline 24 lds R2,_i ldi R24,4 mul R24,R2 movw R30,R0 ldd R0,y+36 ldd R1,y+37 add R30,R0 adc R31,R1 ldd R2,z+0 ldd R3,z+1 ldd R4,z+2 ldd R5,z+3 ldd R18,y+12 ldd R19,y+13 ldi R16,4 ldi R17,0 xcall empy16s movw R30,R16 ldd R0,y+38 ldd R1,y+39 add R30,R0 adc R31,R1 std z+0,R2 std z+1,R3 std z+2,R4 std z+3,R5 .dbline 25 L3: .dbline 17 lds R24,_i subi R24,255 ; addi 1 sts _i,R24 L5: .dbline 17 lds R24,_i cpi R24,8 brsh X0 xjmp L2 X0: .dbline 26 ; { ; x0=x1=x2=0; ; x0=i&0x01; ; x1=(i/2)&0x01; ; x2=(i/4)&0x01; ; xx=x0*4+x1*2+x2; ; dataI[xx]=dataR[i]; //实部的数放在虚部数组中 ; } ; for(i=0;i<8;i++) clr R2 sts _i,R2 xjmp L9 L6: .dbline 27 .dbline 28 lds R2,_i ldi R24,4 mul R24,R2 movw R2,R0 movw R30,R2 ldd R0,y+38 ldd R1,y+39 add R30,R0 adc R31,R1 ldd R4,z+0 ldd R5,z+1 ldd R6,z+2 ldd R7,z+3 movw R30,R2 ldd R0,y+36 ldd R1,y+37 add R30,R0 adc R31,R1 std z+0,R4 std z+1,R5 std z+2,R6 std z+3,R7 .dbline 29 lds R2,_i mul R24,R2 movw R30,R0 ldd R0,y+38 ldd R1,y+39 add R30,R0 adc R31,R1 ldi R16, L10 xcall lpm32 std z+0,R16 std z+1,R17 std z+2,R18 std z+3,R19 .dbline 30 L7: .dbline 26 lds R24,_i subi R24,255 ; addi 1 sts _i,R24 L9: .dbline 26 lds R24,_i cpi R24,8 brsh X1 xjmp L6 X1: .dbline 32 ; { ; dataR[i]=dataI[i]; //将虚部保存的数传回实部 ; dataI[i]=0; ; } ; /************** following code FFT *******************/ ; for(L = 1 ; L <= 3 ; L ++ ) // for (1) L 代表第几级 ldi R24,1 ldi R25,0 std y+25,R25 std y+24,R24 L11: .dbline 33 ; { .dbline 34 ; b = 1 ; ldi R24,1 ldi R25,0 std y+23,R25 std y+22,R24 .dbline 35 ; i = L - 1 ; ldd R24,y+24 ldd R25,y+25 sbiw R24,1 sts _i,R24 xjmp L16 L15: .dbline 37 .dbline 38 ldi R16,2 ldi R17,0 ldd R18,y+22 ldd R19,y+23 xcall empy16s std y+23,R17 std y+22,R16 .dbline 39 lds R24,_i subi R24,1 sts _i,R24 .dbline 40 L16: .dbline 36 ; while ( i > 0 ) //计算第L层旋转因子的个数,即输入口间距 b= 2^(L-1) clr R2 lds R3,_i cp R2,R3 brlo L15 .dbline 42 ; { ; b=b*2; ; i--; ; } ; ; for ( j = 0 ; j <= b - 1 ; j ++ ) // for (2) j 用来控制计算第几个旋转因子 clr R10 clr R11 xjmp L21 L18: .dbline 43 ; { .dbline 44 ; p = 1 ; ldi R24,1 ldi R25,0 movw R14,R24 .dbline 45 ; i = 3 - L ; ldi R24,3 ldd R0,y+24 ldd R1,y+25 sub R24,R0 sbc R25,R1 sts _i,R24 xjmp L23 L22: .dbline 48 .dbline 49 ldi R16,2 ldi R17,0 movw R18,R14 xcall empy16s movw R14,R16 .dbline 50 lds R24,_i subi R24,1 sts _i,R24 .dbline 51 L23: .dbline 47 ; ; while ( i > 0 ) /* p=pow(2,3-L)*j; */ clr R2 lds R3,_i cp R2,R3 brlo L22 .dbline 52 ; { ; p = p * 2 ; ; i -- ; ; } ; p=p*j; movw R18,R10 movw R16,R14 xcall empy16s movw R14,R16 .dbline 54 ; ; for ( k = j ; k < 8 ; k = k + 2 * b ) /* for (3) */ movw R12,R10 xjmp L28 L25: .dbline 55 .dbline 55 ldi R16, L29 xcall lpm32 st -y,R19 st -y,R18 st -y,R17 st -y,R16 movw R16,R14 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 xcall empy32fs ldi R16, L30 xcall lpm32 st -y,R19 st -y,R18 st -y,R17 st -y,R16 xcall div32f xcall fp2int movw R14,R16 .dbline 56 ldi R16,4 ldi R17,0 movw R18,R12 xcall empy16s movw R30,R16 ldd R0,y+36 ldd R1,y+37 add R30,R0 adc R31,R1 ldd R2,z+0 ldd R3,z+1 ldd R4,z+2 ldd R5,z+3 movw R30,R28 std z+0,R2 std z+1,R3 std z+2,R4 std z+3,R5 .dbline 57 ldi R16,4 ldi R17,0 movw R18,R12 xcall empy16s movw R30,R16 ldd R0,y+38 ldd R1,y+39 add R30,R0 adc R31,R1 ldd R2,z+0 ldd R3,z+1 ldd R4,z+2 ldd R5,z+3 movw R30,R28 std z+4,R2 std z+5,R3 std z+6,R4 std z+7,R5 .dbline 58 movw R18,R12 ldd R0,y+22 ldd R1,y+23 add R18,R0 adc R19,R1 ldi R16,4 ldi R17,0 xcall empy16s movw R30,R16 ldd R0,y+36 ldd R1,y+37 add R30,R0 adc R31,R1 ldd R2,z+0 ldd R3,z+1 ldd R4,z+2 ldd R5,z+3 movw R30,R28 std z+8,R2 std z+9,R3 std z+10,R4 std z+11,R5 .dbline 59 movw R16,R14 xcall int2fp xcall _cos movw R2,R16 movw R4,R18 movw R16,R14 xcall int2fp push R2 push R3 push R4 push R5 xcall _sin pop R5 pop R4 pop R3 pop R2 movw R6,R16 movw R8,R18 ldi R16,4 ldi R17,0 movw R18,R12 xcall empy16s movw R24,R16 ldd R0,y+36 ldd R1,y+37 add R24,R0 adc R25,R1 movw R30,R24 ldd R20,z+0 ldd R21,z+1 ldd R22,z+2 ldd R23,z+3 st -y,R23 st -y,R22 st -y,R21 st -y,R20 movw R18,R12 ; stack offset 4 ldd R0,y+26 ldd R1,y+27 add R18,R0 adc R19,R1 ldi R16,4 ldi R17,0 xcall empy16s movw R30,R16 ; stack offset 4 ldd R0,y+40 ldd R1,y+41 add R30,R0 adc R31,R1 ldd R20,z+0 ldd R21,z+1 ldd R22,z+2 ldd R23,z+3 st -y,R23 st -y,R22 st -y,R21 st -y,R20 st -y,R5 st -y,R4 st -y,R3 st -y,R2 xcall empy32fs xcall add32fs movw R18,R12 ; stack offset 4 ldd R0,y+26 ldd R1,y+27 add R18,R0 adc R19,R1 ldi R16,4 ldi R17,0 xcall empy16s movw R30,R16 ; stack offset 4 ldd R0,y+42 ldd R1,y+43 add R30,R0 adc R31,R1 ldd R2,z+0 ldd R3,z+1 ldd R4,z+2 ldd R5,z+3 st -y,R5 st -y,R4 st -y,R3 st -y,R2 st -y,R9 st -y,R8 st -y,R7 st -y,R6 xcall empy32fs xcall add32f movw R30,R24 std z+0,R16 std z+1,R17 std z+2,R18 std z+3,R19 .dbline 60 movw R16,R14 xcall int2fp xcall _sin movw R2,R16 movw R4,R18 movw R16,R14 xcall int2fp push R2 push R3 push R4 push R5 xcall _cos pop R5 pop R4 pop R3 pop R2 movw R6,R16 movw R8,R18 ldi R16,4 ldi R17,0 movw R18,R12 xcall empy16s movw R24,R16 ldd R0,y+38 ldd R1,y+39 add R24,R0 adc R25,R1 movw R30,R24 ldd R20,z+0 ldd R21,z+1 ldd R22,z+2 ldd R23,z+3 st -y,R23 st -y,R22 st -y,R21 st -y,R20 movw R18,R12 ; stack offset 4 ldd R0,y+26 ldd R1,y+27 add R18,R0 adc R19,R1 ldi R16,4 ldi R17,0 xcall empy16s movw R30,R16 ; stack offset 4 ldd R0,y+40 ldd R1,y+41 add R30,R0 adc R31,R1 ldd R20,z+0 ldd R21,z+1 ldd R22,z+2 ldd R23,z+3 st -y,R23 st -y,R22 st -y,R21 st -y,R20 st -y,R5 st -y,R4 st -y,R3 st -y,R2 xcall empy32fs xcall sub32fs movw R18,R12 ; stack offset 4 ldd R0,y+26 ldd R1,y+27 add R18,R0 adc R19,R1 ldi R16,4 ldi R17,0 xcall empy16s movw R30,R16 ; stack offset 4 ldd R0,y+42 ldd R1,y+43 add R30,R0 adc R31,R1 ldd R2,z+0 ldd R3,z+1 ldd R4,z+2 ldd R5,z+3 st -y,R5 st -y,R4 st -y,R3 st -y,R2 st -y,R9 st -y,R8 st -y,R7 st -y,R6 xcall empy32fs xcall add32f movw R30,R24 std z+0,R16 std z+1,R17 std z+2,R18 std z+3,R19 .dbline 61 movw R16,R14 xcall int2fp xcall _cos movw R2,R16 movw R4,R18 movw R16,R14 xcall int2fp push R2 push R3 push R4 push R5 xcall _sin pop R5 pop R4 pop R3 pop R2 movw R6,R16 movw R8,R18 movw R18,R12 ldd R0,y+22 ldd R1,y+23 add R18,R0 adc R19,R1 ldi R16,4 ldi R17,0 xcall empy16s movw R24,R16 ldd R0,y+36 ldd R1,y+37 add R24,R0 adc R25,R1 movw R30,R28 ldd R20,z+0 ldd R21,z+1 ldd R22,z+2 ldd R23,z+3 st -y,R23 st -y,R22 st -y,R21 st -y,R20 movw R30,R24 ldd R20,z+0 ldd R21,z+1 ldd R22,z+2 ldd R23,z+3 st -y,R23 st -y,R22 st -y,R21 st -y,R20 st -y,R5 st -y,R4 st -y,R3 st -y,R2 xcall empy32fs xcall sub32fs movw R18,R12 ; stack offset 4 ldd R0,y+26 ldd R1,y+27 add R18,R0 adc R19,R1 ldi R16,4 ldi R17,0 xcall empy16s movw R30,R16 ; stack offset 4 ldd R0,y+42 ldd R1,y+43 add R30,R0 adc R31,R1 ldd R2,z+0 ldd R3,z+1 ldd R4,z+2 ldd R5,z+3 st -y,R5 st -y,R4 st -y,R3 st -y,R2 st -y,R9 st -y,R8 st -y,R7 st -y,R6 xcall empy32fs xcall sub32f movw R30,R24 std z+0,R16 std z+1,R17 std z+2,R18 std z+3,R19 .dbline 62 movw R16,R14 xcall int2fp xcall _sin movw R2,R16 movw R4,R18 movw R16,R14 xcall int2fp push R2 push R3 push R4 push R5 xcall _cos pop R5 pop R4 pop R3 pop R2 movw R6,R16 movw R8,R18 movw R30,R28 ldd R20,z+4 ldd R21,z+5 ldd R22,z+6 ldd R23,z+7 st -y,R23 st -y,R22 st -y,R21 st -y,R20 movw R30,R28 ; stack offset 4 ldd R20,z+12 ldd R21,z+13 ldd R22,z+14 ldd R23,z+15 st -y,R23 st -y,R22 st -y,R21 st -y,R20 st -y,R5 st -y,R4 st -y,R3 st -y,R2 xcall empy32fs xcall add32fs movw R18,R12 ; stack offset 4 ldd R0,y+26 ldd R1,y+27 add R18,R0 adc R19,R1 ldi R16,4 ldi R17,0 xcall empy16s movw R30,R16 ; stack offset 4 ldd R0,y+42 ldd R1,y+43 add R30,R0 adc R31,R1 ldd R2,z+0 ldd R3,z+1 ldd R4,z+2 ldd R5,z+3 st -y,R5 st -y,R4 st -y,R3 st -y,R2 st -y,R9 st -y,R8 st -y,R7 st -y,R6 xcall empy32fs xcall sub32f movw R18,R12 ldd R0,y+22 ldd R1,y+23 add R18,R0 adc R19,R1 ldi R16,4 ldi R17,0 xcall empy16s movw R30,R16 ldd R0,y+38 ldd R1,y+39 add R30,R0 adc R31,R1 std z+0,R16 std z+1,R17 std z+2,R18 std z+3,R19 .dbline 69 L26: .dbline 54 ldi R16,2 ldi R17,0 ldd R18,y+22 ldd R19,y+23 xcall empy16s add R12,R16 adc R13,R17 L28: .dbline 54 movw R24,R12 cpi R24,8 ldi R30,0 cpc R25,R30 brge X2 xjmp L25 X2: .dbline 71 L19: .dbline 42 movw R24,R10 adiw R24,1 movw R10,R24 L21: .dbline 42 ldd R24,y+22 ldd R25,y+23 sbiw R24,1 cp R24,R10 cpc R25,R11 brlt X3 xjmp L18 X3: .dbline 73 L12: .dbline 32 ldd R24,y+24 ldd R25,y+25 adiw R24,1 std y+25,R25 std y+24,R24 .dbline 32 ldi R24,3 ldi R25,0 ldd R0,y+24 ldd R1,y+25 cp R24,R0 cpc R25,R1 brlt X4 xjmp L11 X4: .dbline 75 ; { p=2*PI*p/8; ; TR = dataR [ k ] ; ; TI = dataI [ k ] ; ; temp = dataR [ k + b ] ; ; dataR[k]=dataR[k]+dataR[k+b]*cos(p)+dataI[k+b]*sin(p); ; dataI[k]=dataI[k]-dataR[k+b]*sin(p)+dataI[k+b]*cos(p); ; dataR[k+b]=TR-dataR[k+b]*cos(p)-dataI[k+b]*sin(p); ; dataI[k+b]=TI+temp*sin(p)-dataI[k+b]*cos(p); ; ; ; /*dataR [ k ] = dataR [ k ] + dataR [ k + b ] * cos_tab [ p ] + dataI [ k + b ] * sin_tab [ p ] ; ; dataI [ k ] = dataI [ k ] - dataR [ k + b ] * sin_tab [ p ] + dataI [ k + b ] * cos_tab [ p ] ; ; dataR [ k + b ] = TR - dataR [ k + b ] * cos_tab [ p ] - dataI [ k + b ] * sin_tab [ p ] ; ; dataI [ k + b ] = TI + temp * sin_tab [ p ] - dataI [ k + b ] * cos_tab [ p ] ;*/ ; } /* END for (3) */ ; ; } /* END for (2) */ ; ; } /* END for (1) */ ; ; for ( i = 0 ; i < 32 ; i ++ ) clr R2 sts _i,R2 xjmp L34 L31: .dbline 76 ; { /* 只需要32次以下的谐波进行分析 */ .dbline 77 ; w [ i ] = sqrt ( dataR [ i ] * dataR [ i ] + dataI [ i ] * dataI [ i ] ) ; lds R2,_i ldi R24,4 mul R24,R2 movw R2,R0 movw R30,R2 ldd R0,y+36 ldd R1,y+37 add R30,R0 adc R31,R1 ldd R4,z+0 ldd R5,z+1 ldd R6,z+2 ldd R7,z+3 movw R30,R28 std z+14,R4 std z+15,R5 std z+16,R6 std z+17,R7 movw R30,R2 ldd R0,y+38 ldd R1,y+39 add R30,R0 adc R31,R1 ldd R2,z+0 ldd R3,z+1 ldd R4,z+2 ldd R5,z+3 movw R30,R28 std z+18,R2 std z+19,R3 std z+20,R4 std z+21,R5 movw R30,R28 ldd R2,z+14 ldd R3,z+15 ldd R4,z+16 ldd R5,z+17 st -y,R5 st -y,R4 st -y,R3 st -y,R2 movw R30,R28 ; stack offset 4 ldd R2,z+18 ldd R3,z+19 ldd R4,z+20 ldd R5,z+21 st -y,R5 st -y,R4 st -y,R3 st -y,R2 xcall empy32fs movw R30,R28 ; stack offset 4 ldd R2,z+22 ldd R3,z+23 ldd R4,z+24 ldd R5,z+25 st -y,R5 st -y,R4 st -y,R3 st -y,R2 movw R30,R28 ; stack offset 8 ldd R2,z+26 ldd R3,z+27 ldd R4,z+28 ldd R5,z+29 st -y,R5 st -y,R4 st -y,R3 st -y,R2 xcall empy32fs xcall add32f xcall _sqrt movw R2,R16 movw R4,R18 st -y,R19 st -y,R18 st -y,R17 st -y,R16 ldi R16, L37 xcall lpm32 st -y,R19 st -y,R18 st -y,R17 st -y,R16 xcall cmp32f brlt L35 st -y,R5 st -y,R4 st -y,R3 st -y,R2 ldi R16, L37 xcall lpm32 st -y,R19 st -y,R18 st -y,R17 st -y,R16 xcall sub32f xcall fp2int movw R24,R16 subi R24,0 ; offset = 32768 sbci R25,128 movw R14,R24 xjmp L36 L35: movw R16,R2 movw R18,R4 xcall fp2int movw R14,R16 L36: ldi R24,<_w ldi R25,>_w lds R30,_i clr R31 add R30,R24 adc R31,R25 std z+0,R14 .dbline 78 ; if ( i ) lds R6,_i tst R6 breq L38 .dbline 79 ; { .dbline 80 ; w [ i ] = w [ i ] / 64 ; clr R7 add R6,R24 adc R7,R25 ldi R17,64 movw R30,R6 ldd R16,z+0 xcall div8u movw R30,R6 std z+0,R16 .dbline 81 ; } L38: .dbline 82 L32: .dbline 75 lds R24,_i subi R24,255 ; addi 1 sts _i,R24 L34: .dbline 75 lds R24,_i cpi R24,32 brsh X5 xjmp L31 X5: .dbline 83 ; } ; w [ 0 ] = w [ 0 ] / 2 ; lds R6,_w lsr R6 sts _w,R6 .dbline -2 L1: adiw R28,26 xcall pop_gset5 adiw R28,4 .dbline 0 ; func end ret .dbsym l xx 12 I .dbsym r x2 14 I .dbsym r x1 10 I .dbsym r x0 12 I .dbsym l L 24 I .dbsym r j 10 I .dbsym l temp 8 D .dbsym l TI 4 D .dbsym l TR 0 D .dbsym l b 22 I .dbsym r p 14 I .dbsym r k 12 I .dbsym l dataI 38 pD .dbsym l dataR 36 pD .dbend .dbfunc e main _main fV .even _main:: .dbline -1 .dbline 88 ; ; } ; ; void main() ; { .dbline 89 ; FFT(dataR,dataI); ldi R18,<_dataI ldi R19,>_dataI ldi R16,<_dataR ldi R17,>_dataR xcall _FFT L41: .dbline 90 L42: .dbline 90 xjmp L41 X6: .dbline -2 L40: .dbline 0 ; func end ret .dbend .area bss(ram, con, rel) .dbfile D:\HJN\Design\AVR\fft\ff.c _w:: .blkb 32 .dbsym e w _w A[32:32]c _i:: .blkb 1 .dbsym e i _i c .area lit(rom, con, rel) L37: .word 0x0,0x4700 L30: .word 0x0,0x4100 L29: .word 0xfda,0x40c9 L10: .word 0x0,0x0