11 - 389 11 - 389
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
SWAP
Instruction
SWAP
• Swaps the values of two variables.
SWAP <variable 1>,<variable 2>
Syntax
Variable 1
• • • •
Specify the variables whose values are exchanged.
Variable 2
• • • •
Examples
SWAP A%,B%
• • • •
Swaps the values of A% and B%.
120
340
A%
B%
120
340
A%
B%
Description
• The SWAP instruction exchanges the value of the variable specified in <variable 1> and
the value of the variable specified in <variable 2>.
• Any types of variables can be specified in <variable> (integer, single-precision, double-
precision, or character string). However, a "Type mismatch" error occurs if the types of two
variables do not match.
Program Example
10 ' This program swaps the data in the variables A and B
20 INPUT "A=";A
:
' Inputs A
30 INPUT "B=";B
:
' Inputs B
40 PRINT "A=";A,"B=";B
:
' Displays the values before the swapping
50 SWAP A,B
:
' Swaps the values
60 PRINT "The values were swapped"
70 PRINT "A=";A,"B=";B
:
' Displays the values after the swapping
80 END
RUN
A=? 1
B=? 2
A= 1 B= 2
The values were swapped
A= 2 B= 1
OK
REMARK
See the BSWAP instruction.
Содержание A1SD51S
Страница 183: ...11 13 11 13 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS RUN Before swap A 0 H924 A 1 H1159 After swap A 0 H1159 A 1 H924 OK...
Страница 331: ...11 161 11 161 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the CON ON OFF STOP and ZOPEN functions and Section 7 4...
Страница 557: ...11 387 11 387 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the CHR SPACE and SPC functions...
Страница 629: ...11 459 11 459 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the ZOPEN ZSEND and ZCNTL instructions and Section 7 3 4...
Страница 645: ...11 475 11 475 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the ZEVENT ZSIGNAL and DEF ZEVENT instructions...