ON 20051028@12:53:51 PM at page: http://www.piclist.com/microchip/math/scale/index.htm#38653.4612152778 James Newton[JMN-EFP-786] published post 38653.4612152778
8-bit value scaled by n-bit fraction I have a lookup table with 4-bit numbers m=0..15. A value t should be scaled according to theese numbers, so that s = t * m/16 Rather than using 16-bit multiplication followed by s>>4, I found a much faster code. As can be seen, the code can be carried out for e.g. 7-bit m-values as well. -------------------- clrf s movf t, W bcf STATUS, C btfsc m, 0 addwf s, F rrf s, F bcf STATUS, C btfsc m, 1 addwf s, F rrf s, F bcf STATUS, C btfsc m, 2 addwf s, F rrf s, F bcf STATUS, C btfsc m, 3 addwf s, F rrf s, F btfsc STATUS, C incf s, F ;nearest value ----------------------- Regards, Anders Jansson|Delete 'P-' before: '' but after: ' OK, I realize now that my scaling algorithm is very similar to the 8x8bit mult by Warren. /A.J |Delete 'P-' before: '' but after: '