On Fri, 17 Oct 2003, Ken Pergola wrote: > Scott Dattalo wrote: > > > Or even better for the 18f series: > > > dcfsnz LoopIteration_LSB,F > > decfsz LoopIteration_MSB,F > > goto beginning_of_loop > > Hi Scott, > > This code does not work (for the intended purpose) -- it will not iterate > the expected number of times. Really? This test code works just fine: Main: LOOPS EQU 25 MOVLW LOW(LOOPS) MOVWF XL MOVLW HIGH(LOOPS + 0x00FF) ; Adjust the high byte. MOVWF XH ; If the low one is nonzero CLRF CH ; A 16-bit counter CLRF CL L2: INFSNZ CL,F ;count the times through. INCF CH,F dcfsnz XL,F ;decrement the 16-bit loop counter. decfsz XH,F bra L2 ; Check to make sure we looped the right number of times. MOVLW LOW(LOOPS) CPFSEQ CL bra Err MOVLW HIGH(LOOPS) CPFSEQ CH bra Err bra Main Err: bra Main The constant has been adjusted by incrementing the high byte only if the low one is non-zero. The only case where it fails is when the value of LOOPS is zero. However, since this is a constant, one could do this: if LOOPS == 0 bra AroundLoop endif Or even better: if LOOPS ; place the looping code here. endif If the loop count is not derived from a constant, then you could do this MOVF XL,W IORWF XH,W BZ AroundLoop ; don't loop if the loop counter is ; zero TSTFSZ XL ; Adjust the high byte INCF XH,F ; only if the low one is nonzero Scott -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu