03 Arithmetic operation

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

ADD/16-bit addition operation

ADD(P)

Add the BIN 16-bit data specified in (S1) and the BIN 16-bit data specified in (S2), and store the result in the device specified in (D).

-[ADD (S1) (S2) (D)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(S1)Addition operation data or the device storing the addition data-32768 to 32767Signed BIN16ANY16_S
(S2)Addition operation data or the device storing the addition data-32768 to 32767Signed BIN16ANY16_S
(D)Device for storing operation results Signed BIN16ANY16_S

Device used

InstructionParameterDevices

Offset modification

Pulse extension

KnXKnYKnMKnSTCDRSDKH[D]XXP
ADDParameter 1
Parameter 2
Parameter 3   

Features

Add the BIN 16-bit data specified in (S1) and the BIN 16-bit data specified in (S2), and store the result of the addition in the device specified in (D).

07-1 Basic instructions_html_8e14b2921161f2d9.png

Related device 

DevicesNameContent
SM151CarryWhen the operation result exceeds 32,767, the carry flag will be (ON).
SM152BorrowWhen the operation result is less than -32,768, the borrow flag will be (ON).
SM153Zero pointWhen the operation result is 0, the zero flag will be (ON).

07-1 Basic instructions_html_f7e7b9fa9918e937.png

Note:  

1.When the source operand and destination operand are specified as the same device:

The source operand and destination operand can also be specified as the same device number.

In this case, if you use continuous execution instructions (ADD, DADD), the result of the addition operation will change every operation cycle.

2.The difference between the ADD instruction and the INC instruction using the +1 addition operation program:

ADD[P] means that every time X001 changes from OFF to ON, the content of D0 is added by one operation.

Although this instruction is very similar to the INCP instruction described later, there are some differences in the following content.

 ADD/ADDP/DADD/DADDP instructionsINC/INCP/DINC/DINCP instructions
Flag bit (zero, borrow, carry)ActionNo action
Calculation result

16-bit

operation result

(S) + (+1) = (D)32767 → 0 → +1 → +2 →32767→-32768→-32767
(S) + (-1) = (D)← -2 ← -1 ← 0 ← -32768——

32-bit

operation result

(S) + (+1) = (D)2147483647 → 0 → +1 → +2 →2147483647 → -2147483648→ -2147483647
(S) + (-1) = (D)← -2 ← -1 ← 0 ← -2147483648——

Error code

Error codeContent
4085HThe output results of (S1) and (S2) in the read application instruction exceed the device range
4086HThe output result of (D) in the write application instruction exceeds the device range

Example

07-1 Basic instructions_html_c88107d9dc85e273.png

Add 10 to the data in (D0), and store the operation result in (D2), that is, (D0) + 10 → (D2).

DADD/32-bit addition operation

DADD(P)

Add the BIN32-bit data specified in (S1) and the BIN32-bit data specified in (S2), and store the result in the device specified in (D).

-[DADD (S1) (S2) (D)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(S1)Addition data or the device storing the addition data-2147483648 to 2147483647Signed BIN32ANY32_S
(S2)Addition data or the device storing the addition data-2147483648 to 2147483647Signed BIN32ANY32_S
(D)Device for storing operation results Signed BIN32ANY32_S

Device used

InstructionParameterDevices

Offset modification

Pulse extension

KnXKnYKnMKnSTCDRSDLCHSCKH[D]XXP
DADDParameter 1
Parameter 2
Parameter 3     

Features

Add the BIN32-bit data specified in (s1) and the BIN32-bit data specified in (s2), and store the result of the addition in the device specified in (d).

07-1 Basic instructions_html_97cb91594c5ae7e4.png

Related device 

DevicesNameContent
SM151CarryWhen the operation result exceeds 32,767, the carry flag will be (ON).
SM152BorrowWhen the operation result is less than -32,768, the borrow flag will be (ON).
SM153Zero pointWhen the operation result is 0, the zero flag will be (ON).

07-1 Basic instructions_html_1e2ca6723b868fb4.png

Note: 

1. When the source operand and destination operand are specified as the same device:

The source operand and destination operand can also be specified as the same device number.

In this case, if you use continuous execution instructions (ADD, DADD), the result of the addition operation will change every operation cycle. Please note.

2. The difference between the ADD instruction and the INC instruction using the +1 addition operation program:

ADD[P] means that every time X001 changes from OFF to ON, the content of D0 is added by one operation.

Although this instruction is very similar to the INCP instruction described later, there are some differences in the following content.

 ADD/ADDP/DADD/DADDP instructionsINC/INCP/DINC/DINCP instructions
Flag bit (zero, borrow, carry)ActionNo action
Calculation result

16-bit

Operation result

(S) + (+1) = (d)32767→0→+1→+2→32767→-32768→-32767
(S) + (-1) = (d)←-2←-1←0←-32768——

33-Bit

operation result

(S) + (+1) = (d)2147483647→0→+1→+2→2147483647→-2147483648→-2147483647
(S) + (-1) = (d)←-2←-1←0←-2147483648——

Error code

Error codeContent
4085HThe output results of (S1) and (S2) in the read application instruction exceed the device range
4086HThe output result of (D) in the write application instruction exceeds the device range

Example

07-1 Basic instructions_html_de63c4a952dfb6d.png

Add 100000 to the data in (D1, D0), and store the result of the operation in (D3, D2), that is, (D1, D0) + 100000 → (D3, D2).

SUB/16-bit subtraction operation

SUB(P)

Subtract the BIN 16-bit data specified in (S1) and the BIN 16-bit data specified in (S2), and store the result in the device specified in (D).

-[SUB (S1) (S2) (D)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(S1)The subtraction data or the device storing the subtraction data-32768 to 32767Signed BIN16ANY16_S
(S2)The subtraction data or the device storing the subtraction data-32768 to 32767Signed BIN16ANY16_S
(D)Device for storing calculation results Signed BIN16ANY16_S

Device used

InstructionParameterDevices

Offset modification

Pulse extension

KnXKnYKnMKnSTCDRSDKH[D]XXP
SUBParameter 1
Parameter 2
Parameter 3   

Features

Subtract the BIN 16-bit data specified in (S1) and the BIN 16-bit data specified in (S2), and store the result of the operation in the device specified in (D).

07-1 Basic instructions_html_cbd3a6fd4cb00b65.png

Related device 

DevicesNameContent
SM151CarryWhen the operation result exceeds 32,767, the carry flag will be (ON).
SM152BorrowWhen the operation result is less than -32,768, the borrow flag will be (ON).
SM153Zero pointWhen the operation result is 0, the zero flag will be (ON).

07-1 Basic instructions_html_ac1f8acda3746b1d.png

Note: 

1. When the source operand and destination operand are specified as the same device:

The source operand and destination operand can also be specified as the same device number.

In this case, if continuous execution type instructions (SUB, DSUB) are used, the result of the subtraction operation will change every operation cycle. Please be careful.

2. The difference between the SUB(P) instruction and the -(P) instruction and DEC(P) instruction executed by the -1 subtraction program

SUB(P) instruction every time X1 changes from OFF to ON, the program of D0 content -1 is similar to -(P) instruction and DEC(P) instruction described later, but the following contents are different.

 SUB/SUBP/DSUB/DSUBP instructionsDEC/DECP/DDEC/DDECP instructions
Flag bit (zero, borrow, carry)ActionNo action
Calculation result16-bit operation result(S)-(+1)=(D)←-2←-1←0←-32768-32768→+32767→32766
(S)-(-1)=(D)+32767→0→+1→+2→——
32-bit operation result(S)-(+1)=(D)←-2←-1←0←-2147483648-2147483648→2147483647→2147483646
(S)-(-1)=(D)2147483647→0→+1→+2→——

Error code

Error codeContent
4085HThe output results of (S1) and (S2) in the read application instruction exceed the device range
4086HThe output result of (D) in the write application instruction exceeds the device range

Example

07-1 Basic instructions_html_bda57d807670bde2.png

Subtract 10 from the data in D0, and store the calculation result in D2, that is, (D0)-10 → (D2).

DSUB/32-bit subtraction operation

DSUB(P)

Subtract the BIN32-bit data specified in (S1) and the BIN32-bit data specified in (S2), and store the result in the device specified in (D).

-[DSUB (S1) (S2) (D)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(S1)The subtraction data or the device storing the subtraction data-2147483648 to 2147483647Signed BIN32ANY32_S
(S2)The subtraction data or the device storing the subtraction data-2147483648 to 2147483647Signed BIN32ANY32_S
(D)Device for storing calculation results Signed BIN32ANY32_S

Device used

InstructionParameterDevices

Offset modification

Pulse extension

KnXKnYKnMKnSTCDRSDLCHSCKH[D]XXP
DSUBParameter 1
Parameter 2
Parameter 3   

Features

Subtract the BIN32-bit data specified in (S1) and the BIN32-bit data specified in (S2), and store the result of the operation in the device specified in (D).

07-1 Basic instructions_html_f37d57bb2a3d8fad.png

Related device

DevicesNameContent
SM151CarryWhen the operation result exceeds 2,147,483,647, the carry flag will be ON.
SM152BorrowWhen the operation result is less than -2,147,483,648, the borrow flag will be ON.
SM153Zero pointWhen the operation result is 0, the zero flag will be ON.

07-1 Basic instructions_html_f61b250c2dec5a2c.png

Note: 

1. When the source operand and destination operand are specified as the same device:

The source operand and destination operand can also be specified as the same device number.

In this case, if continuous execution type instructions (SUB, DSUB) are used, the result of the subtraction operation will change every operation cycle. Please be careful.

2. The difference between the SUB(P) instruction and the -(P) instruction and DEC(P) instruction executed by the -1 subtraction program

SUB(P) instruction every time X1 changes from OFF to ON, the program of D0 content -1 is similar to -(P) instruction and DEC(P) instruction described later, but the following contents are different.

 SUB/SUBP/DSUB/DSUBP instructionsDEC/DECP/DDEC/DDECP instructions
Flag bit (zero, borrow, carry)ActionNo action
Calculation result16-bit operation result(S)-(+1)=(D)←-2←-1←0←-32768-32768→32767→32766
(S)-(-1)=(D)+32767→0→+1→+2→——
32-bit operation result(S)-(+1)=(D)←-2←-1←0←-2147483648-2147483648→2147483647→2147483646
(S)-(-1)=(D)+2147483647→0→+1→+2→——

Error code

Error codeContent
4085HThe output results of (S1) and (S2) in the read application instruction exceed the device range
4086HThe output result of (D) in the write application instruction exceeds the device range

Example

07-1 Basic instructions_html_e0a9b7ee38c72d67.png

Subtract 100000 from the data in (D1,D0), and store the result of the operation in (D3,D2), that is, (D1,D0)-10000 → (D3,D2).

MUL/16-bit multiplication

MUL(P)

Multiply the BIN16 bits specified in (S1) with the BIN16 bits specified in (S2), and store the result in the device specified in (D).

-[MUL (S1) (S2) (D)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(S1)Multiplication operation data or the device storing multiplication operation data-32768 to 32767Signed BIN 16 bitANY16_S
(S2)Multiplication operation data or the device storing multiplication operation data-32768 to 32767Signed BIN 16 bitANY16_S
(D)Device for storing calculation results Signed BIN 32 bitANY32_S

Device used

InstructionParameterDevices

Offset modification

Pulse extension

KnXKnYKnMKnSTCDRSDLCHSCKH[D]XXP
MULParameter 1  
Parameter 2  
Parameter 3   

Features

Multiply the BIN 16-bit data specified in (S1) with the BIN 16-bit data specified in (S2), and store the result of the operation in the device specified in (D).

07-1 Basic instructions_html_7bc795b98291521f.png

(D) is the multiplication result in the case of bit device

• K1: lower 4 bits (B0 to B3)

• K4: Lower 16 bits (B0 to B15)

• K8: Lower 32 bits (B0 to B31)

Error code

Error codeContent
4085HThe output results of (S1) and (S2) in the read application instruction exceed the device range
4086HThe output result of (D) in the write application instruction exceeds the device range

Example

07-1 Basic instructions_html_a72970708460f454.png

Multiply the data in (D0) by (D2), and store the operation result in (D5, D4), that is, (D0) × (D2) → (D5, D4).

DMUL/32-bit multiplication

DMUL(P)

Multiply the 32-bit BIN specified in (S1) and the 32-bit BIN specified in (S2), and store the result in the device specified in (D).

-[DMUL (S1) (S2) (D)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(S1)Multiplication operation data or device storing multiplication operation data-2147483648 to 2147483647Signed BIN 32 bitANY32_S
(S2)Multiplication operation data or device storing multiplication operation data-2147483648 to 2147483647Signed BIN 32 bitANY32_S
(D)Device for storing calculation results Signed BIN64 bitANY64_S

Device used

InstructionParameterDevices

Offset modification

Pulse extension

KnXKnYKnMKnSTCDRSDLCHSCKH[D]XXP
DMULParameter 1
Parameter 2
Parameter 3   

Features

Multiply the BIN32-bit data specified in (S1) and the BIN32-bit data specified in (S2), and store the result of the operation in the device specified in (D).

07-1 Basic instructions_html_1d28943293a84978.png

(D) is the multiplication result in the case of bit device

• K1: lower 4 bits (B0 to B3)

• K4: Lower 16 bits (B0 to B15)

• K8: Lower 32 bits (B0 to B31)

Error code

Error codeContent
4085HThe output results of (S1) and (S2) in the read application instruction exceed the device range
4086HThe output result of (D) in the write application instruction exceeds the device range

Example

07-1 Basic instructions_html_d0ed498dee1bbd2b.png

Multiply the data in (D1, D0) by (D3, D2), and store the result of the operation in ((D7, D6), (D5, D4)), ie (D1, D0) × (D3, D2) → ((D7, D6), (D5, D4)).

DIV/16-bit division operation

DIV(P)

Divide the BIN 16-bit data specified in (S1) with the BIN 16-bit data specified in (S2), and store the result in the device specified in (D).

-[DIV (S1) (S2) (D)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(S1)Division operation data or device storing division operation data-32768 to 32767Signed BIN 16 bitANY16_S
(S2)Division operation data or device storing division operation data-32768 to 32767Signed BIN 16 bitANY16_S
(D)Device for storing calculation results Signed BIN 32 bitANY32_S

Device used

InstructionParameterDevices

Offset modification

Pulse extension

KnXKnYKnMKnSTCDRSDLCHSCKH[D]XXP
DIVParameter 1  
Parameter 2  
Parameter 3   

Features

Divide the BIN 16-bit data specified in (S1) with the BIN 16-bit data specified in (S2), and store the result of the operation in the device specified in (D).

07-1 Basic instructions_html_5b6a7b9968539f80.png

In the case of a word device, the division result uses a 32-bit storage quotient and remainder, and in the case of a bit device, only a 16-bit storage quotient is used.

• Quotient is stored in the lower 16 bits.

• The remainder is stored in the upper 16 bits. (Can only be stored in the case of word devices.)

Note

1. About the opearation result

• The highest bit of the quotient and remainder represents the sign of positive (0) and negative (1).

• When one of (S1) or (S2) is negative, the quotient becomes negative. When (S1) is negative, the remainder becomes negative.

2. The device specified by (D)

• With the digit specification function, when specifying a bit device, the remainder cannot be obtained.

Error code

Error codeContent
4080HThe input of divisor (S2) is 0
4085HThe output results of (S1) and (S2) in the read application instruction exceed the device range
4086HThe output result of (D) in the write application instruction exceeds the device range

Example

07-1 Basic instructions_html_7966aef8d2143e29.png

Divide the data in (D0) by (D2), and store the result of the calculation: the quotient is stored in (D4), and the remainder is stored in (D5), ie (D0)/(D2) → (D4 (quotient)) (D5 ( remainder)).

DDIV/32-bit division operation

DDIV(P)

Divide the BIN32-bit data specified in (S1) with the BIN32-bit data specified in (S2), and store the result in the device specified in (D).

-[DDIV (S1) (S2) (D)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(S1)Division operation data or device storing division operation data-2147483648 to 2147483647Signed BIN 32 bitANY32_S
(S2)Division operation data or device storing division operation data-2147483648 to 2147483647Signed BIN 32 bitANY32_S
(D)Device for storing calculation results Signed BIN64 bitANY64_S

Device used

InstructionParameterDevices

Offset modification

Pulse extension

KnXKnYKnMKnSTCDRSDLCHSCKH[D]XXP
DDIVParameter 1
Parameter 2
Parameter 3   

Features

Divide the BIN32-bit data specified in (S1) with the BIN32-bit data specified in (S2), and store the result of the operation in the device specified in (D).

07-1 Basic instructions_html_1b1dca7a3fa22e30.png

In the case of word devices, the division result uses BIN64 bits to store the quotient and remainder. In the case of bit devices, only the BIN 32-bit storage quotient is used.

Note: 

1. About the operation result

• The highest bit of the quotient and remainder represents the sign of positive (0) and negative (1).

• When one of (S1) or (S2) is negative, the quotient becomes negative. When (S1) is negative, the remainder becomes negative.

2. The specified device of (D)

• With the digit specification function, when a bit device is specified, the remainder cannot be obtained.

Error code

Error codeContent
4080HThe input of divisor (S2) is 0
4085HThe output results of (S1) and (S2) in the read application instruction exceed the device range
4086HThe output result of (D) in the write application instruction exceeds the device range

Example

07-1 Basic instructions_html_21e85706527efeba.png

Divide the data in (D1, D0) by (D3, D2), and store the result of the calculation: the quotient is stored in (D5, D4), and the remainder is stored in (D7, D6), that is (D1, D0)/ (D3, D2) → (D5, D4) (quotient) (D7, D6) (remainder).

INC/16-bit data increment

INC(P)

Add one to the device (BIN 16-bit data) specified in (D).

-[INC (D)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(D)The word device number that stores the data added by one-32768 to 32767Signed BIN 16 bitANY16_S

Device used

InstructionParameterDevices

Offset modification

Pulse extension

KnYKnMKnSTCDRSD[D]XXP
INCParameter 1

Features

Add one to the device (BIN 16-bit data) specified in (D).

07-1 Basic instructions_html_f35c36e39c08072.png

• If the INC(P) instruction is executed when the content of the device specified in (D) is 32767, -32768 will be stored in the device specified in (D).

• Flags (zero, borrow, carry) do not perform actions.

Note:  If the continuous execution (INC) instruction is used, the addition operation will be performed every operation cycle, so care should be taken.

Error code

Error codeContent
4085HThe output results of (D) in the read application instruction exceed the device range
4086HThe output result of (D) in the write application instruction exceeds the device range

Example

07-1 Basic instructions_html_4fe585ed449771bf.png

Add one to the device value specified in D0, that is, (D0) + 1 → (D0).

DINC/32-bit data increment

DINC(P)

Add one to the device (BIN 32-bit data) specified in (D).

-[DINC (D)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(D)The word device number that stores the data added by one-2147483648 to 2147493647Signed BIN 32 bitANY32_S

Device used

InstructionParameterDevices

Offset modification

Pulse extension

KnYKnMKnSTCDRSDLCHSC[D]XXP
DINCParameter 1

Features

Add one to the device (BIN 32-bit data) specified in (D).

07-1 Basic instructions_html_7d13add7bbac367d.png

• When the DINC(P) instruction is executed when the content of the device specified in (D) is 2147483647, -2147483648 will be stored in the device specified in (D).

• Flags (zero, borrow, carry) do not perform actions.

Note:  If the continuous execution (INC) instruction is used, the addition operation will be performed every operation cycle, so care should be taken.

Error code

Error codeContent
4085HThe output results of (D) in the read application instruction exceed the device range
4086HThe output result of (D) in the write application instruction exceeds the device range

Example

07-1 Basic instructions_html_9288e451278259f.png

Add one to the device value specified in (D1, D0), that is, (D1, D0) + 1 → (D1, D0).

DEC/16 bit data decrement

DEC(P)

Minus one for the device (BIN 16-bit data) specified in (D).

-[DEC (D)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(D)The word device number that stores the data minus by one-32768 to 32767Signed BIN 16 bitANY16_S

Device used

InstructionParameterDevices

Offset modification

Pulse extension

KnYKnMKnSTCDRSD[D]XXP
DECParameter 1

Features

Minus one for the device (BIN 16-bit data) specified in (D).

07-1 Basic instructions_html_df1a004773f12e76.png

• If the DEC(P) instruction is executed when the content of the device specified in (D) is -32768, 32767 will be stored in the device specified in (D).

• Flags (zero, borrow, carry) do not perform actions.

Note:  If using continuous execution (DEC) instructions, subtraction will be performed every operation cycle, so care should be taken.

Error code

Error codeContent
4085HThe output results of (D) in the read application instruction exceed the device range
4086HThe output result of (D) in the write application instruction exceeds the device range

Example

07-1 Basic instructions_html_ebee4e241b873490.png

Each time M0 is set, the value of the device specified in D0 will be -1, (D0)-1 → (D0).

DDEC/32-bit data decrement

DDEC(P)

Minus one for the device (BIN 32-bit data) specified in (D).

-[DDEC (D)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(D)The word device number that stores the data minus by one-2147483648 to 2147483647Signed BIN 32 bitANY32_S

Device used

InstructionParameterDevices

Offset modification

Pulse extension

KnYKnMKnSTCDRSDLCHSC[D]XXP
DDECParameter 1

Features

Minus one for the device (BIN 32-bit data) specified in (D).

07-1 Basic instructions_html_7d13add7bbac367d.png

If the DDEC(P) instruction is executed when the content of the device specified in (D) is 0, minus one will be stored in the device specified in (D).

• Flags (zero, borrow, carry) do not perform actions.

Note:  If using continuous execution (DEC) instructions, subtraction will be performed every operation cycle.

Error code

Error codeContent
4085HThe output results of (D) in the read application instruction exceed the device range
4086HThe output result of (D) in the write application instruction exceeds the device range

Example

07-1 Basic instructions_html_2f77792f36a8d549.png

Minus one on the device value specified in (D1, D0), that is, (D1, D0)-1 → (D0).