Chapter 4. Ladder Diagram (LD) Programming
GFK-2950C
February 2018
171
4.8.18
Swap
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.
Other
mnemonic:
SWAP_WORD
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:
B1
B2
B3
B4
B5
B6
B7
B8
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.
Parameter Description
Allowed Operands Optional
Length (??) The number of WORDs or DWORDs to operate on.
1
Length
256
Constant
No
IN
Reference for data to be swapped. (must be the same type as Q) All
No
Q
Reference for swapped data. (must be the same type as IN)
All except S
No
Example for Swap
Two bytes located in bits %I00033 through %I00048 are swapped.
The result is stored in %L00007.
Summary of Contents for PACSystems RX7i
Page 357: ......
Page 466: ...Chapter 9 Diagnostics GFK 2950C February 2018 451...