On Mon, 14 Jul 1997 15:33:00 +0200 David BALDWIN writes: >hi, > > Nice to find someone that's doing PIC development in Belgium! >What are >you working on? For the Swapf, I don't know, but I am using it, and it >works, but I don't understand why we need to do this... The SWAPF instruction swaps the high and low 4 bits of a byte. If a memeory location contains 11100001, SWAPF memloc,W will return 00011110 in W. This is useful for packed BCD operations. But why in an ISR? The reason is that SWAPF doesn't affect the Z status bit but MOVFW (or MOVF file,w) does. The obvious way to save and restore W and STATUS during an ISR would be: int movwf savew ;Save interrupted program's W movfw STATUS ;and STATUS movwf saves [Interrupt service code here, may freely modify W and STATUS] movfw saves ;Get stored status back movwf STATUS movfw savew ;Wrong. Will affect Z. retfie Unlike some processors, in a PIC the Z flag does not always correspond to whether the W register contains zero. The ISR above will force it to, which may cause logical errors in the main program. Since SWAPF doesn't affect Z, it is the less damaging way to recall from memory to W. Relpacing the last movfw with: swapf savew,f ;Put bits in proper order to swap again swapf savew,w ;Restore to W without affecting Z will restore W and STATUS exactly as they were when the program was interrupted.