These all destroy the contents of W. Jon was curious if you could make a routine shorter than 9 instructions that would swap two registers without a temporary register and without destroying what's in W. If your program, however, is so tight that you cannot spare one clock cycle, one memory location, or the contents of W then you likely ought to use another chip, so I suspect this is mostly an acedemic exercise. I did check the piclist website for help in understanding it, and to double check and make sure it isn't there. What I didn't do is go through all the instructions available on the 16x line and see if there is a shorter way of doing it, and it's been awhile since I've done assembly programming. But I am taking a digital design class, and I thought it would be fun to try and do the equations. I'm not sure what mistakes I'm making, but the equations don't work out as I expected (which is why I proved them via perfect induction). I'm curious of the more experienced can share their vast wisdom: XOR does not appear to be associative: A xor ( B xor C ) != ( A xor B ) xor C This has been worked by hand, and my calculator verified the results, but by perfect induction the results are the same A B C | B xor C | A xor B | A xor ( B xor C ) | ( A xor B ) xor C 0 0 0 | 0 | 0 | 0 | 0 0 0 1 | 1 | 0 | 1 | 1 0 1 0 | 1 | 1 | 1 | 1 0 1 1 | 0 | 1 | 0 | 0 1 0 0 | 0 | 1 | 1 | 1 1 0 1 | 1 | 1 | 0 | 0 1 1 0 | 1 | 0 | 0 | 0 1 1 1 | 0 | 0 | 1 | 1 So it would appear to be associative. I suspect I'm just not running my calculations correctly. This applies to the question because the algorithm depends on (A xor B) xor B = A xor (B xor B) = A Anyway... -Adam Germain Morbe wrote: >Hi Jon, > >see my posting of last year as below. > >greetings Germain > >Also greetings to the PICLISTs specialists and to all whos only answer was: >This is a job for the specialists. Notice, the answer is already here in the >archive. > > >----- Original Message ----- >From: Germain Morbe >To: >Sent: Monday, June 18, 2001 8:20 AM >Subject: [PIC]: Swapping Vars w/o Temp > > >>Hi all, >> >>just for info. Swap vars without a 3rd register. >> >> >>start >> movlw 17 >> movwf Variable_1 >> movlw 91 >> movwf Variable_2 >> >>; classic approach: >> >> movf Variable_1,w >> movwf Temp >> movf Variable_2,w >> movwf Variable_1 >> movf Temp,w >> movwf Variable_2 >> >>; smart approach: >> >> movf Variable_1,w >> xorwf Variable_2,w >> xorwf Variable_1,f >> xorwf Variable_2,f >> >> >>Greets Germain >> >> >> > >-- >http://www.piclist.com hint: The PICList is archived three different >ways. See http://www.piclist.com/#archives for details. > > > > > -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.