Robin Abbott of Forest Electronic Developments says:
This might be of use to someone. Recently I had a project where a subroutine took a value in W and saved to a software stack:mov Temp, W mov W, sp ; Stack pointer mov FSR, W ; Point to it mov W, Temp mov 0, WTrouble is it uses a temporary variable which I didn't have (it is in an interrupt). This alternative which makes use of XOR uses no temporary variable at the expense of 1 extra word:
mov FSR, W mov W, sp xor FSR, W xor W, FSR xor FSR, W mov 0, WYou can also use this to swap two variables (say x and y) without a temporary variable leaving X (or Y if order is reversed) in W.
mov W, x ; Get X xor y, W ; Y is now X^Y xor W, y ; W is now (X^y)^X==Y (say OldY) mov x, W ; Now X is OldY xor y, W ; finally Y is (OldX^Y)^Y==OldXI think this may be an old technique - I have vague memories of something similar from the pre-history of programming, but only found a use for
| file: /techref/scenix/lib/math/bit/swap_sx.htm, 1KB, , updated: 2004/8/19 17:14, local time: 2010/3/20 15:07,
38.107.191.112:LOG IN
|
| ©2010 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? Please DO link to this page! Digg it! <A HREF="http://www.piclist.com/techref/scenix/lib/math/bit/swap_sx.htm"> SX Microcontroller Bit Math Method - swap w and f without a temp register</A> |
| Did you find what you needed? |
|
Ubicom SX18 thru SX52, PIC 16c5X compatibile, 50 to 75 MIPS microcontrollers! |
Robotics nuts!Check out http://www.verinet.com/~dlc/ email: dlc@verinet.com... This guy ROCKS! He has made (and sells but also releases code, docs, etc...) for a number of cool little robotic modules including whiskers, IR proximity detect and remote control, Sonar proximity detect, PWM, Servo, compass. Most of these use the little PIC 12C508 controller which costs basically nothing and is soooo tiny.The 4 servos, 2400 baud serial servo controller is a wonder of magic and he sells the programmed chip for $8. Wow! |
.