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 16:14, local time: 2024/12/26 16:04,
3.139.80.194: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_sx.htm"> SX Microcontroller Bit Math Method - swap w and f without a temp register</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to ecomorder.com! |
.