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:movwf Temp movfw sp ; Stack pointer movwf FSR ; Point to it movfw Temp movwf 0Trouble 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:
movwf FSR movfw sp xorwf FSR xorwf FSR,w xorwf FSR movwf 0You 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.
movfw x ; Get X xorwf y ; Y is now X^Y xorwf y,w ; W is now (X^y)^X==Y (say OldY) movwf x ; Now X is OldY xorwf y ; 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.htm, 1KB, , updated: 2000/3/10 16:19, local time: 2024/8/17 02:11,
3.142.195.209:LOG IN
|
©2024 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? <A HREF="http://ecomorder.com/techref/scenix/lib/math/bit/swap.htm"> scenix lib math bit swap</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Ashley Roll has put together a really nice little unit here. Leave off the MAX232 and keep these handy for the few times you need true RS232! |
.