11 - 12 11 - 12
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
Description
• The BSWAP instruction swaps two values in byte units starting from the address specified
by the variable.
Especially, this instruction is used in order to rearrange the I/O data that is communicated
with the external device so that it conforms to the data format of the device used.
A%
C8
H
00
H
64
H
00
H
(0)
(1)
A%
00
H
C8
H
00
H
64
H
(0)
(1)
BSWAP A%( ),0,A%( ),1,1
BSWAP A%( ),2,A%( ),3,1
• An error occurs if the swap starting address in the variable is larger than the array size
specified by the DIM instruction.
• The same variable can be specified to <variable1> and <variable2>.
• Specify the number of swap counts in bytes to <swap count>.
Program Example
10 ' Swaps the contents of array A%(0) and A%(1)
20 DIM A%(1)
:
' Defines the array
30 A%(0)=&H924
:
' Defines a numeric value to the array
40 A%(1)=&H1159
50 PRINT "Before swap"
:
' Displays the value before swapping
60 PRINT "A%(0)=&H";HEX$(A%(0))
70 PRINT "A%(1)=&H";HEX$(A%(1))
80 BSWAP A%( ),0,A%( ),2,2
:
' Swaps
90 PRINT "After swap"
:
' Displays the value after swapping
100 PRINT " A%(0)=&H";HEX$(A%(0))
110 PRINT " A%(1)=&H";HEX$(A%(1))
120 END