www.pudn.com > fft_iccavr.rar > fffff.s
.module fffff.c .area data(ram, con, rel) _dataR:: .blkb 2 .area idata .word 5 .area data(ram, con, rel) .blkb 2 .area idata .word 5 .area data(ram, con, rel) .blkb 2 .area idata .word 5 .area data(ram, con, rel) .blkb 2 .area idata .word 5 .area data(ram, con, rel) .blkb 2 .area idata .word 0 .area data(ram, con, rel) .blkb 2 .area idata .word 0 .area data(ram, con, rel) .blkb 2 .area idata .word 0 .area data(ram, con, rel) .blkb 2 .area idata .word 0 .area data(ram, con, rel) .blkb 2 .area idata .word 5 .area data(ram, con, rel) .blkb 2 .area idata .word 5 .area data(ram, con, rel) .blkb 2 .area idata .word 5 .area data(ram, con, rel) .blkb 2 .area idata .word 5 .area data(ram, con, rel) .blkb 2 .area idata .word 0 .area data(ram, con, rel) .blkb 2 .area idata .word 0 .area data(ram, con, rel) .blkb 2 .area idata .word 0 .area data(ram, con, rel) .blkb 2 .area idata .word 0 .area data(ram, con, rel) .dbfile D:\HJN\Design\AVR\fft\fffff.c .dbsym e dataR _dataR A[32:16]I .area text(rom, con, rel) .dbfile D:\HJN\Design\AVR\fft\fffff.c .dbfunc e FFT _FFT fV ; x6 -> y+22 ; x5 -> y+20 ; x4 -> y+18 ; xx -> y+16 ; x3 -> y+14 ; x2 -> y+12 ; x1 -> R12,R13 ; x0 -> R10,R11 ; L -> y+27 ; j -> R14,R15 ; temp -> y+8 ; TI -> y+4 ; TR -> y+0 ; i -> y+26 ; p -> R10,R11 ; b -> y+24 ; k -> R12,R13 ; dataI -> y+41 ; dataR -> y+39 .even _FFT:: xcall push_arg4 xcall push_gset5 sbiw R28,29 .dbline -1 .dbline 11 ; #include; #include ; #define PI 3.1415926 ; #define qq PI/8 ; ; int dataR[]={5,5,5,5,0,0,0,0,5,5,5,5,0,0,0,0}; ; int dataI[16],w[32]; ; ; ; void FFT(int dataR[],int dataI[]) ; {int x0,x1,x2,x3,x4,x5,x6,xx; .dbline 16 ; unsigned char i; ; int L,j,k,b,p; ; float TR,TI,temp; ; /********** following code invert sequence ************/ ; for(i=0;i<16;i++) clr R0 std y+26,R0 xjmp L5 L2: .dbline 17 .dbline 17 clr R2 clr R3 std y+23,R3 std y+22,R2 std y+21,R3 std y+20,R2 std y+19,R3 std y+18,R2 std y+15,R3 std y+14,R2 std y+13,R3 std y+12,R2 clr R12 clr R13 clr R10 clr R11 .dbline 18 ldd R24,y+26 clr R25 andi R24,1 andi R25,0 movw R10,R24 .dbline 18 ldd R24,y+26 clr R25 asr R25 ror R24 andi R24,1 andi R25,0 movw R12,R24 .dbline 18 ldd R24,y+26 clr R25 asr R25 ror R24 asr R25 ror R24 andi R24,1 andi R25,0 std y+13,R25 std y+12,R24 .dbline 18 ldd R24,y+26 clr R25 asr R25 ror R24 asr R25 ror R24 asr R25 ror R24 andi R24,1 andi R25,0 std y+15,R25 std y+14,R24 .dbline 20 ldi R16,4 ldi R17,0 movw R18,R12 xcall empy16s movw R2,R16 ldi R16,8 ldi R17,0 movw R18,R10 xcall empy16s movw R4,R16 add R4,R2 adc R5,R3 ldd R18,y+12 ldd R19,y+13 ldi R16,2 ldi R17,0 xcall empy16s add R4,R16 adc R5,R17 ldd R2,y+14 ldd R3,y+15 add R4,R2 adc R5,R3 std y+17,R5 std y+16,R4 .dbline 21 ldi R24,2 ldd R0,y+26 mul R24,R0 movw R30,R0 ldd R0,y+39 ldd R1,y+40 add R30,R0 adc R31,R1 ldd R2,z+0 ldd R3,z+1 movw R18,R4 ldi R16,2 ldi R17,0 xcall empy16s movw R30,R16 ldd R0,y+41 ldd R1,y+42 add R30,R0 adc R31,R1 std z+1,R3 std z+0,R2 .dbline 22 L3: .dbline 16 ldd R0,y+26 inc R0 std y+26,R0 L5: .dbline 16 ldd R24,y+26 cpi R24,16 brsh X0 xjmp L2 X0: .dbline 23 ; { x0=x1=x2=x3=x4=x5=x6=0; ; x0=i&0x01; x1=(i>>1)&0x01; x2=(i>>2)&0x01; x3=(i>>3)&0x01; ; //x4=(i>>4)&0x01; x5=(i>>5)&0x01; x6=(i>>6)&0x01; ; xx=x0*8+x1*4+x2*2+x3; ; dataI[xx]=dataR[i]; ; } ; for(i=0;i<16;i++) clr R0 std y+26,R0 xjmp L9 L6: .dbline 24 .dbline 24 ldi R24,2 ldd R0,y+26 mul R24,R0 movw R2,R0 movw R30,R2 ldd R0,y+41 ldd R1,y+42 add R30,R0 adc R31,R1 ldd R4,z+0 ldd R5,z+1 movw R30,R2 ldd R0,y+39 ldd R1,y+40 add R30,R0 adc R31,R1 std z+1,R5 std z+0,R4 .dbline 24 ldd R0,y+26 mul R24,R0 movw R30,R0 ldd R0,y+41 ldd R1,y+42 add R30,R0 adc R31,R1 clr R2 clr R3 std z+1,R3 std z+0,R2 .dbline 24 L7: .dbline 23 ldd R0,y+26 inc R0 std y+26,R0 L9: .dbline 23 ldd R24,y+26 cpi R24,16 brlo L6 .dbline 26 ldi R24,1 ldi R25,0 std y+28,R25 std y+27,R24 L10: .dbline 26 ; { dataR[i]=dataI[i]; dataI[i]=0; } ; /************** following code FFT *******************/ ; for(L=1;L<=4;L++) { /* for(1) */ .dbline 27 ; b=1; i=L-1; ldi R24,1 ldi R25,0 std y+25,R25 std y+24,R24 .dbline 27 ldd R24,y+27 ldd R25,y+28 sbiw R24,1 std y+26,R24 xjmp L15 L14: .dbline 29 .dbline 29 ldi R16,2 ldi R17,0 ldd R18,y+24 ldd R19,y+25 xcall empy16s std y+25,R17 std y+24,R16 .dbline 29 ldd R0,y+26 dec R0 std y+26,R0 .dbline 29 L15: .dbline 28 ; while(i>0) clr R2 ldd R0,y+26 cp R2,R0 brlo L14 .dbline 30 ; {b=b*2; i--;} /* b= 2^(L-1) */ ; for(j=0;j<=b-1;j++) /* for (2) */ clr R14 clr R15 xjmp L20 L17: .dbline 31 ; { p=1; i=4-L; .dbline 31 ldi R24,1 ldi R25,0 movw R10,R24 .dbline 31 ldi R24,4 ldd R0,y+27 ldd R1,y+28 sub R24,R0 sbc R25,R1 std y+26,R24 xjmp L22 L21: .dbline 33 .dbline 33 ldi R16,2 ldi R17,0 movw R18,R10 xcall empy16s movw R10,R16 .dbline 33 ldd R0,y+26 dec R0 std y+26,R0 .dbline 33 L22: .dbline 32 ; while(i>0) /* p=pow(2,7-L)*j; */ clr R2 ldd R0,y+26 cp R2,R0 brlo L21 .dbline 34 ; {p=p*2; i--;} ; p=p*j;for(k=j;k<16;k=k+2*b) /* for (3) */ movw R18,R14 movw R16,R10 xcall empy16s movw R10,R16 .dbline 34 movw R12,R14 xjmp L27 L24: .dbline 35 .dbline 35 ldi R16,2 ldi R17,0 movw R18,R12 xcall empy16s movw R30,R16 ldd R0,y+39 ldd R1,y+40 add R30,R0 adc R31,R1 ldd R16,z+0 ldd R17,z+1 xcall int2fp movw R30,R28 std z+0,R16 std z+1,R17 std z+2,R18 std z+3,R19 .dbline 35 ldi R16,2 ldi R17,0 movw R18,R12 xcall empy16s movw R30,R16 ldd R0,y+41 ldd R1,y+42 add R30,R0 adc R31,R1 ldd R16,z+0 ldd R17,z+1 xcall int2fp movw R30,R28 std z+4,R16 std z+5,R17 std z+6,R18 std z+7,R19 .dbline 35 movw R18,R12 ldd R0,y+24 ldd R1,y+25 add R18,R0 adc R19,R1 ldi R16,2 ldi R17,0 xcall empy16s movw R30,R16 ldd R0,y+39 ldd R1,y+40 add R30,R0 adc R31,R1 ldd R16,z+0 ldd R17,z+1 xcall int2fp movw R30,R28 std z+8,R16 std z+9,R17 std z+10,R18 std z+11,R19 .dbline 36 ldi R16, L28 xcall lpm32 st -y,R19 st -y,R18 st -y,R17 st -y,R16 movw R16,R10 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 xcall empy32f xcall _cos movw R2,R16 movw R4,R18 ldi R16, L28 xcall lpm32 st -y,R19 st -y,R18 st -y,R17 st -y,R16 movw R16,R10 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 xcall empy32f 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,2 ldi R17,0 movw R18,R12 xcall empy16s movw R24,R16 ldd R0,y+39 ldd R1,y+40 add R24,R0 adc R25,R1 movw R30,R24 ldd R16,z+0 ldd R17,z+1 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 movw R18,R12 ; stack offset 4 ldd R0,y+28 ldd R1,y+29 add R18,R0 adc R19,R1 ldi R16,2 ldi R17,0 xcall empy16s movw R30,R16 ; stack offset 4 ldd R0,y+43 ldd R1,y+44 add R30,R0 adc R31,R1 ldd R16,z+0 ldd R17,z+1 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 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+28 ldd R1,y+29 add R18,R0 adc R19,R1 ldi R16,2 ldi R17,0 xcall empy16s movw R30,R16 ; stack offset 4 ldd R0,y+45 ldd R1,y+46 add R30,R0 adc R31,R1 ldd R16,z+0 ldd R17,z+1 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 st -y,R9 st -y,R8 st -y,R7 st -y,R6 xcall empy32fs xcall add32f xcall fp2int movw R30,R24 std z+1,R17 std z+0,R16 .dbline 37 ldi R16, L28 xcall lpm32 st -y,R19 st -y,R18 st -y,R17 st -y,R16 movw R16,R10 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 xcall empy32f xcall _sin movw R2,R16 movw R4,R18 ldi R16, L28 xcall lpm32 st -y,R19 st -y,R18 st -y,R17 st -y,R16 movw R16,R10 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 xcall empy32f 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,2 ldi R17,0 movw R18,R12 xcall empy16s movw R24,R16 ldd R0,y+41 ldd R1,y+42 add R24,R0 adc R25,R1 movw R30,R24 ldd R16,z+0 ldd R17,z+1 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 movw R18,R12 ; stack offset 4 ldd R0,y+28 ldd R1,y+29 add R18,R0 adc R19,R1 ldi R16,2 ldi R17,0 xcall empy16s movw R30,R16 ; stack offset 4 ldd R0,y+43 ldd R1,y+44 add R30,R0 adc R31,R1 ldd R16,z+0 ldd R17,z+1 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 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+28 ldd R1,y+29 add R18,R0 adc R19,R1 ldi R16,2 ldi R17,0 xcall empy16s movw R30,R16 ; stack offset 4 ldd R0,y+45 ldd R1,y+46 add R30,R0 adc R31,R1 ldd R16,z+0 ldd R17,z+1 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 st -y,R9 st -y,R8 st -y,R7 st -y,R6 xcall empy32fs xcall add32f xcall fp2int movw R30,R24 std z+1,R17 std z+0,R16 .dbline 38 ldi R16, L28 xcall lpm32 st -y,R19 st -y,R18 st -y,R17 st -y,R16 movw R16,R10 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 xcall empy32f xcall _cos movw R2,R16 movw R4,R18 ldi R16, L28 xcall lpm32 st -y,R19 st -y,R18 st -y,R17 st -y,R16 movw R16,R10 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 xcall empy32f 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+24 ldd R1,y+25 add R18,R0 adc R19,R1 ldi R16,2 ldi R17,0 xcall empy16s movw R24,R16 ldd R0,y+39 ldd R1,y+40 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 R16,z+0 ldd R17,z+1 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 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+28 ldd R1,y+29 add R18,R0 adc R19,R1 ldi R16,2 ldi R17,0 xcall empy16s movw R30,R16 ; stack offset 4 ldd R0,y+45 ldd R1,y+46 add R30,R0 adc R31,R1 ldd R16,z+0 ldd R17,z+1 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 st -y,R9 st -y,R8 st -y,R7 st -y,R6 xcall empy32fs xcall sub32f xcall fp2int movw R30,R24 std z+1,R17 std z+0,R16 .dbline 39 ldi R16, L28 xcall lpm32 st -y,R19 st -y,R18 st -y,R17 st -y,R16 movw R16,R10 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 xcall empy32f xcall _sin movw R2,R16 movw R4,R18 ldi R16, L28 xcall lpm32 st -y,R19 st -y,R18 st -y,R17 st -y,R16 movw R16,R10 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 xcall empy32f 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+28 ldd R1,y+29 add R18,R0 adc R19,R1 ldi R16,2 ldi R17,0 xcall empy16s movw R30,R16 ; stack offset 4 ldd R0,y+45 ldd R1,y+46 add R30,R0 adc R31,R1 ldd R16,z+0 ldd R17,z+1 xcall int2fp st -y,R19 st -y,R18 st -y,R17 st -y,R16 st -y,R9 st -y,R8 st -y,R7 st -y,R6 xcall empy32fs xcall sub32f xcall fp2int movw R2,R16 movw R18,R12 ldd R0,y+24 ldd R1,y+25 add R18,R0 adc R19,R1 ldi R16,2 ldi R17,0 xcall empy16s movw R30,R16 ldd R0,y+41 ldd R1,y+42 add R30,R0 adc R31,R1 std z+1,R3 std z+0,R2 .dbline 40 L25: .dbline 34 ldi R16,2 ldi R17,0 ldd R18,y+24 ldd R19,y+25 xcall empy16s add R12,R16 adc R13,R17 L27: .dbline 34 movw R24,R12 cpi R24,16 ldi R30,0 cpc R25,R30 brge X1 xjmp L24 X1: .dbline 41 L18: .dbline 30 movw R24,R14 adiw R24,1 movw R14,R24 L20: .dbline 30 ldd R24,y+24 ldd R25,y+25 sbiw R24,1 cp R24,R14 cpc R25,R15 brlt X2 xjmp L17 X2: .dbline 42 L11: .dbline 26 ldd R24,y+27 ldd R25,y+28 adiw R24,1 std y+28,R25 std y+27,R24 .dbline 26 ldi R24,4 ldi R25,0 ldd R0,y+27 ldd R1,y+28 cp R24,R0 cpc R25,R1 brlt X3 xjmp L10 X3: .dbline 43 ; { TR=dataR[k]; TI=dataI[k]; temp=dataR[k+b]; ; dataR[k]=dataR[k]+dataR[k+b]*cos(qq*p)+dataI[k+b]*sin(qq*p); ; dataI[k]=dataI[k]-dataR[k+b]*sin(qq*p)+dataI[k+b]*cos(qq*p); ; dataR[k+b]=TR-dataR[k+b]*cos(qq*p)-dataI[k+b]*sin(qq*p); ; dataI[k+b]=TI+temp*sin(qq*p)-dataI[k+b]*cos(qq*p); ; } /* END for (3) */ ; } /* END for (2) */ ; } /* END for (1) */ ; for(i=0;i<32;i++) clr R0 std y+26,R0 xjmp L32 L29: .dbline 44 ; { /* 只需要32次以下的谐波进行分析 */ .dbline 45 ; w[i]=sqrt(dataR[i]*dataR[i]+dataI[i]*dataI[i]); ldi R24,2 ldd R0,y+26 mul R24,R0 movw R2,R0 movw R30,R2 ldd R0,y+39 ldd R1,y+40 add R30,R0 adc R31,R1 ldd R4,z+0 ldd R5,z+1 movw R30,R2 ldd R0,y+41 ldd R1,y+42 add R30,R0 adc R31,R1 ldd R6,z+0 ldd R7,z+1 movw R18,R6 movw R16,R6 xcall empy16s movw R6,R16 movw R18,R4 movw R16,R4 xcall empy16s add R16,R6 adc R17,R7 xcall int2fp push R2 push R3 xcall _sqrt pop R3 pop R2 ldi R24,<_w ldi R25,>_w movw R30,R2 add R30,R24 adc R31,R25 xcall fp2int std z+1,R17 std z+0,R16 .dbline 46 ; if(!i) ldd R0,y+26 tst R0 brne L33 .dbline 47 ; { .dbline 48 ; w[i]=w[i]/64; ldi R24,2 mul R24,R0 movw R2,R0 ldi R24,<_w ldi R25,>_w add R2,R24 adc R3,R25 ldi R18,64 ldi R19,0 movw R30,R2 ldd R16,z+0 ldd R17,z+1 xcall div16s movw R30,R2 std z+1,R17 std z+0,R16 .dbline 49 ; } L33: .dbline 50 L30: .dbline 43 ldd R0,y+26 inc R0 std y+26,R0 L32: .dbline 43 ldd R24,y+26 cpi R24,32 brsh X4 xjmp L29 X4: .dbline 51 ; } ; w[0]=w[0]/2; ldi R18,2 ldi R19,0 lds R16,_w lds R17,_w+1 xcall div16s sts _w+1,R17 sts _w,R16 .dbline -2 L1: adiw R28,29 xcall pop_gset5 adiw R28,4 .dbline 0 ; func end ret .dbsym l x6 22 I .dbsym l x5 20 I .dbsym l x4 18 I .dbsym l xx 16 I .dbsym l x3 14 I .dbsym l x2 12 I .dbsym r x1 12 I .dbsym r x0 10 I .dbsym l L 27 I .dbsym r j 14 I .dbsym l temp 8 D .dbsym l TI 4 D .dbsym l TR 0 D .dbsym l i 26 c .dbsym r p 10 I .dbsym l b 24 I .dbsym r k 12 I .dbsym l dataI 41 pI .dbsym l dataR 39 pI .dbend .dbfunc e main _main fV .even _main:: .dbline -1 .dbline 55 ; } /* END FFT */ ; ; void main () ; { .dbline 56 ; FFT(dataR,dataI); ldi R18,<_dataI ldi R19,>_dataI ldi R16,<_dataR ldi R17,>_dataR xcall _FFT L36: .dbline 57 L37: .dbline 57 xjmp L36 X5: .dbline -2 L35: .dbline 0 ; func end ret .dbend .area bss(ram, con, rel) .dbfile D:\HJN\Design\AVR\fft\fffff.c _w:: .blkb 64 .dbsym e w _w A[64:32]I _dataI:: .blkb 32 .dbsym e dataI _dataI A[32:16]I .area lit(rom, con, rel) L28: .word 0xfda,0x3ec9