04 Move and compare

Last modified by Wecon on 2025/09/03 21:03

CMP instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
CMPComparison instruction16NoCMP S1 S2 D7
CMPP16Yes7
DCMP32No13
DCMPP32Yes13

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.

OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S1    
S2    
D             

Program example

7-3Move and compare_html_672fc7a91c81c662.jpg

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

NameFunctionBitsPulse typeInstruction formatStep
ZCPRegional comparison16NoZCP S1 S2 S D7
ZCPP16Yes7
DZCP32No13
DZCP32Yes13

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.

✎Note: If the upper limit is less than the lower limit, the upper limit is considered equal to the lower limit.

OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S1     
S2     
S     
D             

Program example

7-3Move and compare_html_c50ce4676b83f0f0.jpg

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

NameFunctionBitsPulse typeInstruction formatStep
MOVMoves data from one storage area to a new storage area16NoMOV S D7
MOVP16Yes7
DMOV32No13
DMOVP32Yes13

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.

OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S     
D        

Program example

7-3Move and compare_html_63375e0f97aaffe1.jpg

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

NameFunctionBit(bits)Pulse typeInstruction formatStep
SMOVShift Move16NoSMOV S M1 M2 D n11
SMOVP16Yes11

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.

OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S       
M1              
M2              
D        
n              

Program example

7-3Move and compare_html_48fa719e1026dc06.jpg

7-3Move and compare_html_e534a9aa917b173f.jpg

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

NameFunctionBitsPulse typeInstruction formatStep
CMLCopies and inverts the source bit pattern to a specified destination16NoCML S D5
CMLP16Yes5
DCML32No13
DCMLP32Yes13

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.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S     
D        

Program example

Example 1:

7-3Move and compare_html_4000eebfee28cea.jpg

Example 2:

7-3Move and compare_html_4c65a7fd9a7dc666.jpg

This program is equal to the below ladder diagrams.

7-3Move and compare_html_7461c87bb822614f.jpg

Example 3:

7-3Move and compare_html_e2175c6ded744b63.jpg

BMOV instruction

Instruction description

NameFunctionBitPulse typeInstruction formatStep
BMOVCopies a specified block of multiple data elements to a new destination16NoBMOV S D n7
BMOVP16Yes7

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.

7-3Move and compare_html_c645fa580437088e.jpg

When the operand is bit device, the digit number of S and D need to be the same.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S         
D          
nConstant n=0 to 512

Program example

7-3Move and compare_html_22db5b59455aaf81.jpg

Result

7-3Move and compare_html_495118782198828d.jpg

FMOV instruction

Instruction description

NameFunctionBitsPulse typeInstruction formatStep
FMOVCopies a single data device to a range of destination devices16NoMOV S D n7
FMOVP16Yes7
DFMOV32No13
DFMOVP32Yes13

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.

OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S       
D          
nConstant, n=1 to512

Program example

7-3Move and compare_html_d9b4a3ac38311c49.jpg

When M8 is on, k100→D100, k100→D101, k100→D102, k100→D103.

XCH instruction

Instruction description

NameFunctionBitsPulse typeInstruction formatStep
XCHData in the designated devices is exchanged16NoXCH S D5
XCHP16Yes5
DXCH32No9
DXCHP32Yes9

The contents of the two destination devices S and D are swapped, i.e. the complete word devices are exchanged.

OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S          
D          

Program example

7-3Move and compare_html_fedbe33fa98b559b.png

 Example 1:

7-3Move and compare_html_f11050348326c6bf.jpg

Example 2:

7-3Move and compare_html_fbd85cc43fa9377f.png

7-3Move and compare_html_28cf590a9d5c90f8.jpg

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

NameFunctionBitsPulse typeInstruction formatStep
BCDConverts binary numbers to BCD equivalents / Converts floating point data to scientific format16NoBCD S D5
BCDP16Yes5
DBCD32No9
DBCDP32Yes9

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.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S       
D       

Programming example

7-3Move and compare_html_adf65a6fbcb01118.jpg

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

NameFunctionBitsPulse typeInstruction formatStep
BINConverts BCD umbers to their binary equivalent /Converts scientific format data to floating point format16NoBIN S D5
BINP16Yes5
DBIN32No9
DBINP32Yes9

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.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S       
D       

Program example

7-3Move and compare_html_a99ac786bd9a7c9c.jpg

When M8 is ON, K1Y0 (BCD value) will be converted into BIN and stored in the D200.