ON 20031212@6:29:42 AM at page: http://www.piclist.com/techref/microchip/math/bit/whatbit.htm GB-adinet-IC4 Gonzalo Damian Barco Code:
;Gonzalo Barco ;A looped approach (a bit smaller and lot slower) ;In case you are sure there's at least one bit set you can loose the first bsf COMPACT4BIT MACRO FILE ;Returns bit 3 set on error (no bits set) local loop, tail bsf STATUS, C ;To be sure we don't looooooooooooop forever clrw ;Clear counter loop: rrf FILE, F ;Send bits off the edge... btfsc STATUS, C ;...on to STATUS, C goto tail ;If we hit the bit... stop addlw 1 ;Otherwise add to the counter... goto loop ;...and keep looping tail: movwf FILE ;Overwrite source with result ENDM