212
4
4 Instructions4.5.5 Other Data Processing
XCH: Data exchange
◆
Overview
When driving conditions are met, the XCH instruction exchanges the data in S and D.
XCH S D
Data exchange Applicable model:
H3U
S Data 1 Word element 1 that stores the data to be exchanged
16-bit instruction
(5 steps)
XCH: Continuous
execution
XCHP: Pulse
execution
32-bit instruction (9
steps)
DXCH: Continuous
execution
DXCHP: Pulse
execution
D Data 2 Word element 2 that stores the data to be exchanged
◆
Operands
Operand
Bit Element Word Element
System·User System·User Bit Designation Indexed Address Constant
Real
Number
S X Y M T C S SM D R T C SD KnX KnY KnM KnS KnSM
V,Z
Modication K H E
D X Y M T C S SM D R T C SD KnX KnY KnM KnS KnSM
V,Z
Modication K H E
Note: The elements in gray background are supported.
◆
Function
The XCH instruction requires contact driving and has two operands. It exchanges the values in S and D.
Example 1:
M8
ǒXCHP D110 D120Ǔ
D110=K180
D120=K200
Before execution
D110=K200
D120=K180
After execution
Example 2:
Before execution
After execution
M8
ǒDXCHP D110 D120Ǔ
D110=K180
D120=K200
D111=K150
D121=K100
D110=K200
D120=K180
D111=K100
D121=K150
When the special variable M8160 is set to 1 and the addresses of D and S are the same, the higher eight
bits and the lower eight bits are exchanged in both 16- and 32-bit operations. The XCH instruction is
equivalent to the SWAP instruction. The SWAP instruction is generally used.