On Sun, 7 Sep 1997 16:43:42 -0400 Sean Breheny writes: >Also, if >you want to swap, you would need an intermediate variable,... Swapping 2 bytes the conventional way with an intermediate variable is straightforward: movfw B movwf tmp ;Save B for when it is replaced by A movfw A ;Copy A into B movwf B movfw tmp ;Old value of B movwf A ;into A There is a better way using a fairly well-known but not immediately obvious "trick" which hasn't been seen on PICLIST lately: movfw A ;W = A xorwf B,w ;W = A xor B xorwf A,f ;A = A xor A xor B = B xorwf B,w ;W = A xor B xor B = A movwf B ;B = A This saves one instruction word and the temporary location over the conventional method. The core idea of this routine may also be used to swap W and B, something difficult to do otherwise: ; Enter with W = A xorwf B,w ;W = A xor B xorwf B,f ;B = A xor B xor B = A xorwf B,w ;W = A xor B xor A = B ; Exit with W = B, and B = old W. [Swapping bytes by using rlf instructions to move them one bit at a time through Carry bit] >You can't use a loop here because that would affect the C bit of the >Status >reg. On the 12 and 14-bit PICs, the only instructions which affect the Carry bit are the add, subtract, and rotate ones. The decfsz instruction commonly used for loop control doesn't affect any status bits. So the swap by rotate method could be coded as a loop, using a RAM location to count loops. Using W to count loops would affect the C bit but if the swap can affect W there are better ways to do it.