Chapter 4. Ladder Diagram (LD) ProgrammingGFK-2950C February 2018 1714.8.18 SwapThe SWAP function is used to swap two bytes within a word (SWAPWORD) or two words within a double word (SWAP DWORD). The SWAPcan be performed over a wide range of memory by specifying a lengthgreater than 1. If that is done, the data in each word or double wordwithin the specified length is swapped.Othermnemonic:SWAP_WORDWhen the SWAP function receives power flow, it swaps the data in reference IN and places theswapped data into output reference Q. The function passes power to the right whenever it receivespower.PACSystems CPUs use the Intel convention for storing word data in bytes. They store the leastsignificant byte of a word in address n and the most significant byte in address n+1. Many VMEmodules follow the Motorola convention of storing the most significant byte in address n and theleast significant byte in address n+1.The PACSystems CPU assigns byte address 1 to the same storage location regardless of the byteconvention used by the other device. However, because of the difference in byte significance, wordand 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. Inaddition, for multiword data items, the words must be swapped end-for-end on a word basis. Forexample, a 64-bit real number transferred to the PACSystems CPU from a Motorola-conventionmodule must be byte-swapped and word-reversed, either before or after reading, as shown below:B1 B2 B3 B4 B5 B6 B7 B8Character (ASCII) strings or BCD data require no adjustment since the Intel and Motorolaconventions for storage of character strings are identical.Operands for SwapThe two parameters, IN and Q, must both be the same type, WORD or DWORD.Parameter Description Allowed Operands OptionalLength (??) The number of WORDs or DWORDs to operate on.1 Length 256Constant NoIN Reference for data to be swapped. (must be the same type as Q) All NoQ Reference for swapped data. (must be the same type as IN) All except S NoExample for SwapTwo bytes located in bits %I00033 through %I00048 are swapped.The result is stored in %L00007.