For what it's worth, here is a C implementation of a log (to base 2) routine. Parameter x (unsigned 16bit integer) is converted to its log to base 2 (8-bit unsigned int scaled up by 16 so that the most significant 4 bits are the exponent and the least significant 4 bits are the fraction). Args approaching 65535 will cause an overflow so watch out for this. An arg of 0 returns 0. The conversion from a base 2 log to a base 10 log is performed by multiplying the result by log10(2) = 0.30102996... which, for our low precision purposes may be approximated by 0.3. The beauty of 0.3 is that the techniques in the parallel thread (regarding division by 10) may be used: Multiply by 3 then divide by 10. Anyway, for audio purposes it's often good enough to leave the result in base 2 since a factor of 2 is very close to 3dB, which is convenient for bar graph display etc. The code should convert to PIC assembler in a straightforward manner. The lookup table would obviously be hard-coded (all 17 entries if LKP_BITS is 4). The result accuracy is +1/16 to -1/32 - this is skewed because of the simple-minded rounding technique. Note that the lookup table contains the following: 0: 0 1: 1 2: 3 3: 4 4: 5 5: 6 6: 7 7: 8 8: 9 9: 10 10: 11 11: 12 12: 13 13: 14 14: 15 15: 15 16: 16 which is so nearly linear that you could use code instead and perhaps save a few words. Regards, SJH Canberra, Australia ----Cut here---- #include #include typedef unsigned short word; /* Input type */ typedef unsigned char byte; /* Output type */ #define LKP_BITS 4 /* Number of bits (past leading 1 bit) to use for indexing log lookup table */ #define LKP_ENT (1<> (14-LKP_BITS)) + 1) >> 1; #else /* Otherwise error is asymmetric and twice as bad, but saves some fooling around */ x >>= 15-LKP_BITS; #endif return (p2 + lookup[x]); } int main(int argc, char ** argv) { float fx, flogx, falogx; word x; byte alogx; init_lkp(); for (fx = 4095; fx <= 8192; fx += 4096/64) { x = fx; flogx = log2((float)x); /* Compute 'exact' */ alogx = alog(x); /* Compute int approx */ falogx = (float)alogx/LKP_SCALE; /* Rescale, and convert to float */ printf("x = %5d log10(x) = %-10.5g alog(x) = %-10.5g diff = %-10.5g\n", x, flogx, falogx, flogx-falogx); } return 0; } ----Cut here----