On Mon, 29 Sep 1997 12:42:41 -0500 John Payson writes: [The routine below complements C without affecting W, but it needs a temporary RAM 'tmp'] >> bcf tmp,0 ;Use value of 0 >> skpc ;if carry is 1 >> bsf tmp,0 ;if carry 0, use 1. >> rrf tmp,f ;New bit to carry bit. >If you add an "rlf tmp,f" to the beginning of that, then "tmp" will be >unaffected (though making it conditional will be a little harder). No, this won't work because the rotate would put the original carry bit which needs to be tested into bit 0 of tmp-- which is the same bit that needs to be modified. So you'd need to use gotos to make sure it is modified properly. No advantage over modifying C in place. >From an information theory point of view, there are only 9 bits active, C and the 8 bits of tmp. So there isn't an extra bit to use to develop a new value while still saving all 8 bits of tmp. One could use brute-force on a single extra bit (The Z bit in the STATUS register being a possible choice as a rather expendable bit): ; First, put complement of C into 'bit' bcf bit ;Assume new value will be 0 skpc bsf bit ;C = 0, therefore new value is 1. ; Then copy 'bit' into C clrc ;Set C to 0 btfsc bit ;if bit is 0 setc ;if bit 1, C = 1 At 6 instructions/6 cycles this routine isn't anything to write home about though, maybe not even competitive with the goto ones. (For those not familiar with the Microchip assembler, skpc, clrc, etc. are predefined macros for bit operations on the Carry bit in the STATUS register)