04 Move and compare
CMP instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
CMP | Comparison instruction | 16 | No | CMP S1 S2 D | 7 |
CMPP | 16 | Yes | 7 | ||
DCMP | 32 | No | 13 | ||
DCMPP | 32 | Yes | 13 |
This instruction compares two operational variables and outputs the comparison result to a specified bit variable. The operands are all algebra compared according to signed data.
D will occupy 3 continue bit variables address.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S1 | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | ||||
S2 | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | ||||
D | √ | √ | √ |
Program example
When X0=ON, M0 or M1 or M2 will be ON.
When X0=OFF, CMP will not be executed, M0, M1 and M2 keep the initial state. If user wants to clear the result of comparison, RST or ZRST could be used.
By series or parallel M0, M1 and M2 to achieve the results of ≤ or ≥ or ≠.
ZCP instruction
Instruction description
Name | Function | Bits | Pulse type | Instruction format | Step |
ZCP | Regional comparison | 16 | No | ZCP S1 S2 S D | 7 |
ZCPP | 16 | Yes | 7 | ||
DZCP | 32 | No | 13 | ||
DZCP | 32 | Yes | 13 |
The operation is the same as the CMP instruction, except a single data value (S) is compared against a data range (S1~S2).
- S is less than S1 and S2 - bit device D is ON
- S is equal to or between S1 and S2 - bit device D +1 is ON
- S is greater than both S1 and S2 - bit device D +2 is ON
- S1: Lower limit of comparison area
- S2: Upper limit of comparison area
- S: Comparison variable
- D: Storage cell of comparison result; it will occupy three continuous bit variables.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S1 | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||
S2 | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||
D | √ | √ | √ |
Program example
When X0=ON, M3 or M4 or M5 will be ON.
When X0=OFF, ZCP will not be executed, M3, m4 and m5 keep the initial state. If user wants to clear the result of comparison, RST or ZRST could be used.
MOV instruction
Instruction description
Name | Function | Bits | Pulse type | Instruction format | Step |
MOV | Moves data from one storage area to a new storage area | 16 | No | MOV S D | 7 |
MOVP | 16 | Yes | 7 | ||
DMOV | 32 | No | 13 | ||
DMOVP | 32 | Yes | 13 |
The content of the source device (S) is copied to the destination (D) device when the control input is active. If the MOV instruction is not driven, no operation takes place.
For 32bit instructions (DMOV), two devices will be copied to the destination device, for example DMOV D1 D5, the result is D1→D5, D2→D6.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||
D | √ | √ | √ | √ | √ | √ | √ | √ |
Program example
When M0 is on, D2=K4, when M0 becomes off, D2 keeps the initial value. Only when user copy another value to D2 or power off the plc or set plc off and on again, the value of D2 will change.
SMOV instruction
Instruction description
Name | Function | Bit(bits) | Pulse type | Instruction format | Step |
SMOV | Shift Move | 16 | No | SMOV S M1 M2 D n | 11 |
SMOVP | 16 | Yes | 11 |
This instruction copies a specified number of digits from a 4 digit decimal source (S) and places them at a specified location within a destination (D) number (also a 4 digit decimal). The existing data in the destination is overwritten.
- M1 - The source position of the 1st digit to be moved
- M2 - The number of source digits to be moved
- n- The destination position for the first digit
Allows BCD numbers to be manipulated in exactly the same way as the ‘normal’ SMOV manipulates decimal numbers, i.e. This instruction copies a specified number of digits from a 4 digit BCD source (S) and places them at a specified location within a destination (D) number (also a 4 digit BCD number).
To select the BCD mode the SMOV instruction is coupled with special M coil M8168 which is driven ON. Please remember that this is a ‘mode’ setting operation and will be active, i.e. all SMOV instructions will operate in BCD format until the mode is reset, i.e. M8168 is forced OFF.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||||
M1 | √ | √ | ||||||||||||||
M2 | √ | √ | ||||||||||||||
D | √ | √ | √ | √ | √ | √ | √ | √ | ||||||||
n | √ | √ |
Program example
Suppose D8=K1234, D2=K5678, then when m8168 is off (bcd mode), set m2, then the value of D2 becomes K5128.
When m8168 is on (bin mode) and D8=H04D2=K1234, D2=H162E=K5678, set m2, then D2=H104E=K4174
CML instruction
Instruction description
Name | Function | Bits | Pulse type | Instruction format | Step |
CML | Copies and inverts the source bit pattern to a specified destination | 16 | No | CML S D | 5 |
CMLP | 16 | Yes | 5 | ||
DCML | 32 | No | 13 | ||
DCMLP | 32 | Yes | 13 |
A copy of each data bit within the source device (S) is inverted and then moved to a designated destination (D).
This means each occurrence of a ‘1’ in the source data will become a ‘0’ in the destination data while each source digit which is ‘0’ will become a ‘1’. If the destination area is smaller than the source data then only the directly mapping bit devices will be processed.
Operand | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||
D | √ | √ | √ | √ | √ | √ | √ | √ |
Program example
Example 1:
Example 2:
This program is equal to the below ladder diagrams.
Example 3:
BMOV instruction
Instruction description
Name | Function | Bit | Pulse type | Instruction format | Step |
BMOV | Copies a specified block of multiple data elements to a new destination | 16 | No | BMOV S D n | 7 |
BMOVP | 16 | Yes | 7 |
A quantity of consecutively occurring data elements could be copied to a new destination. The source data is identified as a device head address (S) and a quantity of consecutive data elements . This is moved to the destination device (D) for the same number of elements .
When the special variable is M8024=ON, the transmission direction is opposite, i.e. S becomes the destination address, D becomes the source address.
When the operand is bit device, the digit number of S and D need to be the same.
Operand | Bit device | Word device | ||||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |||
S | √ | √ | √ | √ | √ | √ | √ | |||||||||||
D | √ | √ | √ | √ | √ | √ | ||||||||||||
n | Constant n=0 to 512 |
Program example
Result
FMOV instruction
Instruction description
Name | Function | Bits | Pulse type | Instruction format | Step |
FMOV | Copies a single data device to a range of destination devices | 16 | No | MOV S D n | 7 |
FMOVP | 16 | Yes | 7 | ||
DFMOV | 32 | No | 13 | ||
DFMOVP | 32 | Yes | 13 |
The data stored in the source device (S) is copied to every device within the destination range. The range is specified by a device head address (D) and a quantity of consecutive elements . If the specified number of destination devices exceeds the available space at the destination location, then only the available destination devices will be written to.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||||
D | √ | √ | √ | √ | √ | √ | ||||||||||
n | Constant, n=1 to512 |
Program example
When M8 is on, k100→D100, k100→D101, k100→D102, k100→D103.
XCH instruction
Instruction description
Name | Function | Bits | Pulse type | Instruction format | Step |
XCH | Data in the designated devices is exchanged | 16 | No | XCH S D | 5 |
XCHP | 16 | Yes | 5 | ||
DXCH | 32 | No | 9 | ||
DXCHP | 32 | Yes | 9 |
The contents of the two destination devices S and D are swapped, i.e. the complete word devices are exchanged.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | ||||||||||
D | √ | √ | √ | √ | √ | √ |
Program example
Example 1:
Example 2:
This function is equivalent to SWAP the bytes within each word of the designated devices D1 are exchanged when ‘byte mode flag’ M8160 is ON. Please note that the mode will remain active until it is reset, i.e. M8160 is forced OFF.
BCD instruction
Instruction description
Name | Function | Bits | Pulse type | Instruction format | Step |
BCD | Converts binary numbers to BCD equivalents / Converts floating point data to scientific format | 16 | No | BCD S D | 5 |
BCDP | 16 | Yes | 5 | ||
DBCD | 32 | No | 9 | ||
DBCDP | 32 | Yes | 9 |
The binary source data (S) is converted into an equivalent BCD number and stored at the destination device (D).
If the converted BCD number exceeds the operational ranges of 0 to 9,999 (16-bit operation) and 0 to 99,999,999 (32-bit operation) an error will occur. M8067 will be ON, and D8067 will record the error code.
Operand | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||||
D | √ | √ | √ | √ | √ | √ | √ | √ | √ |
Programming example
The BIN value in D200 is converted to BCD value and the units’ digit is saved in K1Y0 (Y0 to Y3).
- If D200=H000E (hex) =K14 (decimal), then Y0~Y3=0100(BIN).
- If D200=H0028 (hex) =K40 (decimal), then Y0~Y3=0000(BIN).
BIN instruction
Instruction description
Name | Function | Bits | Pulse type | Instruction format | Step |
BIN | Converts BCD umbers to their binary equivalent /Converts scientific format data to floating point format | 16 | No | BIN S D | 5 |
BINP | 16 | Yes | 5 | ||
DBIN | 32 | No | 9 | ||
DBINP | 32 | Yes | 9 |
The BCD source data (S) is converted into an equivalent binary number and stored at the destination device (D). If the source data is not provided in a BCD format an error will occur. This instruction could be used to read in data directly from thumbwheel switches.
The value of S (BCD) ranges from 0 to 9999(16-bit) and 0 to 99999999(32-bit)
When the value of D is not BCD, there will be an error, and M8067 will be ON.
Operand | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||||
D | √ | √ | √ | √ | √ | √ | √ | √ | √ |
Program example
When M8 is ON, K1Y0 (BCD value) will be converted into BIN and stored in the D200.