Skip to main content

Subtraction (WORD)

Instruction Parameters

Supported PLC Series

XPnA/1RXPnBXPnEXPnFCP3A/B/P/U
CP4A~D/U
CPnECPnFBPPLC-S

Supported Data Registers

MXYKLFTCSZRQD@DConstant
S1-
S2-
D----

Supported Flags

FlagBitSupport
ErrorF11.0
ZeroF11.1-
CarryF11.2-

Number of Steps

Steps
4

Operands

OperandDescription
S1The first operand.
Entries are WORD data registers or constants.

The signed value range is -32,768 ~ 32,767 (216).
The unsigned value range is 0 ~ 65,535 (216-1).
The Hexadecimal value range is H0000 ~ HFFFF.
S2The second operand.
Entries are WORD data registers or constants.

The signed value range is -32,768 ~ 32,767 (216).
The unsigned value range is 0 ~ 65,535 (216-1).
The Hexadecimal value range is H0000 ~ HFFFF.
DThe third operand.
Entries are only WORD data registers.
This is where the difference is saved.

Notice

Error Flag (F11.0) Notice

The error flag, F11.0, will be ON for one scan when the address of the data register assigned by @D exceeds the range of the data register, D. The range of the data register, D, is dependent on the CPU type.

F11.0 turns ON when the value of the data for subtracting exceeds the data register assigned to S1 or S2.

Tip: Signed Notation

The signed value range for SUB and SUBP is -32,768 ~ 32,767 (216).

  • If the SUB or SUBP instruction is executed while the value for the difference data register, D, is 32,767, the overflow value for the difference data register, D, will begin at -32,768 if the value being subtracted is -1.
  • If the SUB or SUBP instruction is executed while the value for the difference data register, D, is -32,768, the overflow value for the difference data register, D, will begin at 32,767 if the value being subtracted is 1.
Tip: Operand Subtraction Format

S2 is subtracted from S1.
(S1 - S2)

Examples