J=E1hn Bal=E1zs writes: > In my variable there are only 00h-63h (0d-99d). And I want divide it by = > 10... I tought there is a very simple method, but I don't know it. = > = > So, it seems the fastest method is the the LOOKUP table, it takes a few = > cycles but more than 100 rows, the shortest (row) method is more than = > 100 cycles. Here's an intermediate speed, and intermediate program store use, version, between LUT versions and shift and loop versions in both dimensions. Since you know that the dividend is less than 100: div10 movwf rem ; Assumes called with dividend in W, and that clrf quo ; bank selection is allready set for access to movlw D'80' ; rem and quo. subwf rem,W ; rem >=3D 80? BNC div10a ; No (rem-80 borrowed) movwf rem ; Remove 80 from rem (could have subwf rem,F) bsf quo,3 ; "add" 8 to quotient div10a movlw D'40' subwf rem,W ; What's left in rem >=3D 40? BNC div10b movwf rem bsf quo,2 ; "add" 4 to quotient div10b movlw D'20' subwf rem,W BNC div10c movwf rem bsf quo,1 div10c movlw D'10' subwf rem,W BNC div10d movwf rem bsf quo,0 div10d ; Quotiend now in quo, remainder in rem swapf quo,W ; One way to return is as BCD, quotient to high iorwf rem,W ; nibble and the remainder in the low nibble. return The time for everything, including call and return, is max 32 cycles, min 28 cycles (28 plus the number of one bits in the quotiend). If you don't want it as a subroutine, and you're happy to read your results from rem and quo, and the dividend is already in a file register that you're happy to use as rem, then the range, still including the clearing of quo, is 21 to 25 cycles. Except for the hack of creating a two digit BCD return value, and interpreting the quotiend as binary, rathern than BCD, this actually works for dividends up to 159. If you want dividends up to the whole unsigned byte (255), you could include a compare with 160 stage before the compare with 80 stage. The extra stage adds 6 cycles if it sets the bit and 5 if it doesn't. If you want a BCD quotient, then use 100 instead of 160 to work for dividends up to 199, or add both a 200 and 100 section for dividends up to 255. Bill -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist