Actually, this has an AVERAGE number of cycles per loop of very close to 3, since the first goto is only skipped 1/256th of the time. Sean At 09:42 AM 5/7/99 +0800, you wrote: >Hi Scott, > >How about, 5 cycles per loop, doesn't use W: > > clrf lo > clrf hi > >loop incfsz lo,f > goto $+2 > incfsz hi,f > goto loop > >regards, >Reggie > >-- >e-mail: rberdin@bigfoot.com >ICQ#: 31651436 >URL: http://www.bigfoot.com/~rberdin > > >Scott Dattalo wrote: >> >> Guys & Alice >> >> It seems like there's been several questions about delay loops in the >> last few weeks. So I thought it'd be interesting to see if we could turn >> this into a challenge: >> >> Create a delay loop that can loop for up to 2^16 times while mininmizing >> the number of cycles per iteration. For example: >> >> clrf lo >> clrf hi >> >> movlw 1 >> >> loop: >> >> addwf lo,f ;increment the low byte >> skpnc ;if low byte rolls over >> addwf hi,f ; then increment the high byte >> >> skpc ;We're done if the high byte rolls over. >> goto loop >> >> This will loop 2^16 times and each pass through the loop is 6 cycles. >> >> I've got a solution that takes 5 cycles per iteration and doesn't use W >> (oh I shouldn't have said that - now you know the answer!). >> >> Any takers? >> >> Scott > | | Sean Breheny | Amateur Radio Callsign: KA3YXM | Electrical Engineering Student \--------------=---------------- Save lives, please look at http://www.all.org Personal page: http://www.people.cornell.edu/pages/shb7 mailto:shb7@cornell.edu ICQ #: 3329174