Greg Young wrote: > I'm not even sure the posted version will work. It begins by > performing a rotation, the results of which is checks for > zero/non-zero. Yet, the initialize state of the carry (which is > shifted in bit 7 of TEST) is unknown. If initially set, it would > blow the algorithm (I think)... Greg: Yeah, you're right... Thanks for catching that. There should be a "CLRC" before the "RRF". That'll teach me to write code online instead of pasting from my text editor, I guess. > For more compact code, why not just add -3 until it overflows or > zeroes. Something like (assuming a 14-bit core): > > Div3 MOVF TEST,W ; W = Value to Test (Set Z) > :next BTFSC Z ; If Z Set, Divisible by Zero > RETLW 1 > ADDLW -3 ; Check Next Iteration > BTFSC C ; Done if Overflow > goto :next ; Continue til Done > RETLW 0 ; Done > As you obviously realize, your code won't work on a 12-bit PIC. Also, it's a lot slower than the "challenge" code, and it slows WAY down when it's scaled up to 16 bits. I guess I worded the challenge unclearly... I should have said: The challenge is to write a faster routine, or one which executes at essentially the same speed but is shorter. Thanks again for pointing out my error... -Andy Andrew Warren - fastfwd@ix.netcom.com Fast Forward Engineering, Vista, California http://www.geocities.com/SiliconValley/2499