> This routine is compact, but unreliable in case of RAM disruption: > clrc ;Shift in a 0. > rlf scanbit,f ;Do the shift. > skpnc ;Skip if 1 didn't come out. > rlf scanbit,f ;If 1 came out, put it to bit 0. > > If the RAM location 'scanbit' contains a value other than one of the form > having a single 1 and 7 zeros, it won't work. The point about self-stabilizing vs non-self-stabilizing code is an important one (if a glitch that may occur once every few days disrupts operation for a few seconds that's often not as bad as one that disrupts operation indef- initely). > Now consider this routine: > > clrc ;Shift in a 0 > rlf scanbit,f ;Rotate it in. > movf scanbit,f ;Test if new value is 0 > skpnz ;It's not, shifted value OK. > bsf scanbit,0 ;Reset scan to first bit. If it's okay (or desirable) to have the result in W as well as F, it can be done safely in 4 cycles: movlw 1 btfss scanbit,7 rlf scanbit,w movwf scanbit