On Sep 29, 2010, at 6:34 PM, David Duffy (AVD) wrote: > On 30/09/2010 10:47 AM, David Duffy (AVD) wrote: >> I have the need to load a 3 byte counter, then decrement in an >> interrupt, detecting (set a flag) when the counter reaches 0x000000. How about something like this? It seems to work OK in sim, but I =20 can't say I've used it in real code. It terminates when the count =20 reaches -1 instead of zero (I say that's more useful anyway!) On the plus side, it'll work on 12bit cores, and is easily =20 extensible. On the minus side, it trashes W, (and the -1 vs 0 thing.) It need not be =20 a subroutine It does that elegant and sneaky thing where multi skip instructions =20 skip because they're skipping over the parts that would have changed =20 the bits so they wouldn't skip... dec3: ;; decrement a 3-byte number (b3:b2:b1). ;; Return 0 in W when it reaches -1, 0 otherwise. movlw -1 addwf b1, f ;decrement low byte. btfss STATUS,C ; wrapped? addwf b2, f ; W still -1; dec mid byte btfss STATUS,C addwf b3, f ; W still -1; dec high byte btfss STATUS,C retlw 0 ; result is -1 exit_nz: retlw -1 --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .