N STEENKAMP [M.ING E&E] wrote: > I have been stuck now for at least 1/2 hour trying to figure out a > way to conditionally complement the carry flag on an '84. The best > I could come up with was: > > comf STATUS, W > movwf Temp > btfsc My_Flags, Complement_Carry > rrf Temp, W > > This just doesn't feel like the right way! > > I also tried: > movlw 01h > btfsc MyFlags, Complement_Carry > xorwf STATUS, F > > but it didn't work. I was hoping that the xorwf instruction would > operate as normal and change the carry flag and afterwards set the Z > flag if the result was 0, but C is totally protected from being > modified. Niki: Yes, you're right... It works like this: If you use an instruction whose destination is the status register, and if that instruction can modify the Carry, Zero, OR the Decimal-Carry flags, then the values that your instruction explicitly writes to ALL THREE of those bits are ignored and the Carry, Zero, and/or Decimal-Carry flags are set by the processor as appropriate. When the PIC executes the "XORWF STATUS" instruction in your example code, the Zero, Carry, and Decimal-Carry flags are unchanged, then the Zero flag is adjusted. This behavior is fully documented in the data books. > Has anyone got a better approach (preferably one that does not need > a file register)? Yes: MOVF STATUS,W BTFSC Complement_Carry XORLW 1 MOVWF STATUS -Andy === Meet other PICLIST members at the Embedded Systems Conference: === 6:30 pm on Wednesday, 1 October, at Bytecraft Limited's booth. === === For more information on the Embedded Systems Conference, === see: http://www.embedsyscon.com/ === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering - Vista, California === http://www.geocities.com/SiliconValley/2499