Dear All, Recently I needed assembly code for a 16-bit 1:256 FIR low-pass filter. First I had a look in the PIClist source code library, but I could not find= what I needed. I clearly did not look in the right place, because the code must be there - that's what i= t says on the tin anyway: "Huge, really... the code you need is here....". ;-) Or perhaps everyone has moved to programming in C ? Finally, I ended up writing the code myself (see below) and was wondering i= f a C compiler would produce the same (or better) code. Please let me know if the code is worth adding to the PIClist source code l= ibrary (or where I can find it). The code uses the improved instruction set that is available in the "newer"= PICs. Cheers, Andries ;--------------------------------------------------------------------------= ------------------------------------------------------------ ; 1:256 Finite Impuls Response Filter for 16-bit values - Andries Tip 2012 ;--------------------------------------------------------------------------= ------------------------------------------------------------ CBLOCK h'070' ; variables available from any bank setpoint1 ; setpoint is the 16-bit input value setpoint2 ; average0 ; average2:average1 is the filtered output = value average1 ; average0 is the fractional part average2 ; temp ; temporary value used in calculation ENDC ;--------------------------------------------------------------------------= ------------------------------------------------------------ FIR_256_16BIT ; average =3D (255*average + = setpoint)/256 movf average0,w ; average =3D 256*average - a= verage =3D 255*average sublw d'0' ; prepare carry movwf temp ; save value for rounding lat= er, otherwise we cannot reach 65535 movf average1,w ; subwfb average0,f ; movf average2,w ; subwfb average1,f ; movlw d'0' ; subwfb average2,f ; movlw d'255' ; average =3D round((average = + setpoint)/256) addwf temp,w ; movf setpoint1,w ; addwfc average0,f ; movf setpoint2,w ; addwfc average1,f ; clrw ; addwfc average2,f ; ;--------------------------------------------------------------------------= ------------------------------------------------------------ --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .