Bob Fehrenbach wrote: > I haven't tested this but adding one line and changing one branch > destination would cause the carry to be cleared only if it were set. > This might provide a small speed advantage. > > > DIVBY3: BCF STATUS, C ;Omitted in first posting. > NO_C: RRF TEST ;New label > BNC NODEC > > SKPNZ > RETLW 0 > > DECF TEST > BCF STATUS, C ;Added line > NODEC: SKPZ > GOTO NO_C ;Changed destination > RETLW 1 Bob: Yes, this cuts about 2.5 cycles (on average) from the execution time. Good call. > I am curious as to why anyone would want to know if a number were > divisible by three, or is this an academic exercise? Bill Cornutt's answer ("It is the classic solution to the 'one potato, two potato' problem") would, of course, be the USUAL reason, but my need for the routine is a little different: The "divisible by 3" routine is only the first step of a much larger process: I'm trying to see if the input number is EQUAL to 3. Here's how it works: First, I check for divisibility by 3. If the number passes that test, I then make sure that it's not also divisible by 2. After that, I use Eric Smith's routine for checking whether a number's within a certain range... I start with a range of [0-255], then progressively narrow the range, one step at a time, to [2-4]. At this point, if the input number's passed all those tests, I'm pretty sure that it may be equal to 3. To make ABSOLUTELY sure, though, I check bits 2-7 of the number individually, verifying that each is clear, then I check bits 0 and 1 and verify that they're both set. Since this is a very critical aplication, though, even THIS isn't enough. To get that last little bit of certainty, I divide 4,294,967,296 by the input number. If the answer's 1,431,655,765, (with no remainder), I asume that the input number was indeed equal to 3. Finally, I double-check my assumption using the following code: XORLW 3 BZ ITS_EQUAL_TO_3 -Andy Andrew Warren - fastfwd@ix.netcom.com Fast Forward Engineering, Vista, California http://www.geocities.com/SiliconValley/2499