Swap
Swaps SRAM-Variables and Array-Elements. Use the command to swap two different Variables or the Low/High-Values of a Variable.
Syntax 1: - swaps Low/High-Values dependent on Data-Type
- Swap Variable
Syntax 2: - swaps 2 Variables
Example for Syntax 1:
dim a as byte dim b as word dim c as long a=&hab b=&haabb c=&haabbccdd print "a = 0x";hex(a) ' output: "a = 0xAB" print "b = 0x";hex(b) ' output: "a = 0xAABB" print "c = 0x";hex(c) ' output: "a = 0xAABBCCDD" swap a ' swaps Low/High-Nibble swap b ' swaps Low/High-Byte swap c ' swaps Low/High-Word print "a = 0x";hex(a) ' output: "a = 0xBA" print "b = 0x";hex(b) ' output: "a = 0xBBAA" print "c = 0x";hex(c) ' output: "a = 0xCCDDAABB"
Example for Syntax 2:
dim a,b,v(4) as byte dim c,d as word a=1 b=2 c=3 d=4 ' swap Variables swap a,b ' swaps values of a and b swap c,d ' swaps values of c and d swap v(2),v(4) ' swaps values of array elements 3 and 5