SUB
Subtracts Value2 from Value1 and stores the result in Result.
Ladder Representation
Block Structure
| Variable Type | Name | Data Type | Description |
|---|---|---|---|
| VAR_INPUT | EN | BOOL | Block enabling. |
| VAR_INPUT | Value1 | BYTE USINT SINT WORD UINT INT DWORD UDINT DINT REAL | Minuend of the operation. |
| VAR_INPUT | Value2 | BYTE USINT SINT WORD UINT INT DWORD UDINT DINT REAL | Subtrahend of the operation. |
| VAR_OUTPUT | Done | BOOL | End of operation. |
| VAR_OUTPUT | Result | BYTE USINT SINT WORD UINT INT DWORD UDINT DINT REAL | Variable that stores the operation result. |
Operation
When EN is TRUE, the block writes the subtraction result between Value1 and Value2 to Result.
If the operation completes without errors, Done is set. If an operation error occurs, Done remains FALSE and Result keeps its previous value.
When EN is FALSE, Result remains unchanged and Done remains FALSE.
Execution Flowchart

Examples
- Ladder Example
- Structured Text Example
This example subtracts VALUE2 from VALUE1 and stores the final result in RESULT.
This example subtracts VALUE2 from VALUE1 and stores the final result in RESULT. The block accepts arguments with different signs.
This example subtracts VALUE2 from VALUE1. The final result, 141, cannot be stored in RESULT because it is outside the accepted range for SINT. For this reason, RESULT remains unchanged and the output is disabled.
The following Structured Text code applies the same logic shown in the Ladder example.
VAR
VALUE1 : SINT := 52;
VALUE2 : SINT := -17;
RESULT : SINT;
END_VAR
RESULT := FB_SUB(
EN:=DI1,
Value1:=VALUE1,
Value2:=VALUE2,
Done=>DO1);