On Fri, 7 May 1999, Scott Dattalo wrote: > Here's another solution that gives two extra cycles for other stuff > (like CLRWDT or testing an I/O bit) > > clrf lo > clrf hi > > loop1 > > nop ;2 free cycles executed 255 out of 256 > nop ;iterations > > loop2 > > decfsz lo,f ;or incfsz > goto loop1 > decfsz hi,f ;if low byte rolls over, dec hi byte, > goto loop2 ;but don't branch to the beginning. After a little churning, I found a 3 cycle solution: clrf lo clrf hi loop decfsz lo,f goto loop ;lo is zero right now. decf hi,f skpnz goto done ;or perhaps return ;okay, we've gotta lot of choices here ; ;we could do this: ; incf lo,f ; nop ;or clrwdt ; incf lo,f ; goto loop ; ;But I like this: bsf lo,1 ;Equivalent to 2 incf's nop ;Two free cycles nop ;everytime lo rolls over goto loop ;Or if you wanted more free cycles: ; bsf lo,2 ;Equivalent to 4 incf's ; goto $+1 ;Eight free cycles ; goto $+1 ;everytime lo rolls ; goto $+1 ;over ; goto $+1 ; ; goto loop ; ;Of course, you could preset the lo byte ;to any value and then have the remaining ;cycles evailable for other stuff. ; Like everything I comment, this untested :). The time at which the lo byte is incremented does not happen exactly every third cycle after it rolls over. In fact, some values of lo are skipped altogether. However, the total number of cycles between the beginning of the loop and the 'goto done' instruction is 2^16 * 3. This kind of loop would be useful if you wanted to have a fixed delay AND still be able to do other things too. Scott