# Subtract Instruction in Ladder Logic

KronoTech

PLC

Basic

Counters

Timer

Arithmetic

SUB

MUL

DIV

DDV

Comparison

Functions

Trig Functions

RSLogix 5000

Structured Text

HMI

Instruments

>

## SUB - Subtract

When rung conditions are true, the SUB output instruction subtracts Source B from Source A and stores the result in the destination. Source A and Source B can either be values or addresses that contain values, however Source A and Source B cannot both be constants.

#### Example 1

Equation: N7:10 = N7:10 - 5

Source A = n7:10 = 23276, Source B = 5, Destination = N7:10 = 23271.

#### Example 2

Equation: N7:13 = N7:11 - N7:12

Source A = N7:11 = 32700, Source B = N7:12 = 69 , Destination = 32767 (why..). The result is invalid since the maximum negative value in a register is -32768, therfore the result is invalid and the overflow bit is on.

Clearing minor error that might be generated if we have an underflow.

#### Note

• If the destination value is < -32768 then the underflow bit S:0/1 bit will be set hence setting the minor bit error S:5/0. If this error is not cleared then it will case major error.
• Can not program Source A and Source B as constant, at least one of them should be a variable.