The SWAP function is used to swap two bytes within a word (SWAP
WORD) or two words within a double word (SWAP DWORD). The SWAP
can be performed over a wide range of memory by specifying a length
greater than 1. If that is done, the data in each word or double word
within the specified length is swapped.
When the SWAP function receives power flow, it swaps the data in reference IN and places the
swapped data into output reference Q. The function passes power to the right whenever it receives
power.
PACSystems CPUs use the Intel convention for storing word data in bytes. They store the least
significant byte of a word in address n and the most significant byte in address n+1. Many VME
modules follow the Motorola convention of storing the most significant byte in address n and the
least significant byte in address n+1.
The PACSystems CPU assigns byte address 1 to the same storage location regardless of the byte
convention used by the other device. However, because of the difference in byte significance, word
and multiword data, for example, 16-bit integers (INT, UINT), 32-bit integers (DINT) or floating point
(REAL) numbers, must be adjusted when being transferred to or from Motorola-convention modules.
In these cases, the two bytes in each word must be swapped, either before or after the transfer. In
addition, for multiword data items, the words must be swapped end-for-end on a word basis. For
example, a 64-bit real number transferred to the PACSystems CPU from a Motorola-convention
module must be byte-swapped and word-reversed, either before or after reading, as shown below:
Character (ASCII) strings or BCD data require no adjustment since the Intel and Motorola
conventions for storage of character strings are identical.
Operands for Swap
The two parameters, IN and Q, must both be the same type, WORD or DWORD.