> -----Original Message----- > From: Scott Dattalo [SMTP:scott@DATTALO.COM] > Sent: Tuesday, July 18, 2000 6:47 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]: Better way to rotate? > > set_bit: > > movf bitmask,w > > iorwf indf,f > btfsc new_state,0 > xorwf indf,f > > clrc > rlf bitmask,w > rlf bitmask,f > > btfsc bitmask,0 > incf fsr,f > > > 9 words/cycles in assembly, with the same caveats as the above routine > (i.e. byteptr, which is fsr, and bitmask both need pre-initialization). > > Scott > Superb, I wish my brain worked that well. I never seem to consider using XOR, I have OR and AND far to firmly embedded into my boolean logic lobe :o) Just one thing, I think the btfsc should really be a btfss (you wish to perform the xor if new_state is zero). This is one of those tricky functions that seems very hard to optimize in C. Very timely thread though, I need to do something very similar in a project I'm working on the moment. Regards Mike -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.