Math (output instruction)

ADD: Add

Writes A plus B into the destination while the rung has power.

Also called: addition, sum, A + B.

ADD(number, a, b, real)

Arguments

NameWhat it isAcceptsDefault
destinationWhat the instruction acts ona registerrequired
aValue Aa number or a tag0
bValue Ba number or a tag1
realFloating pointtrue or falsefalse

Arguments are positional and this table is generated from the simulator's own instruction registry, so it always matches what the engine accepts.

What it does

ADD does what it says, and like every math instruction in ladder it runs on every scan the rung is true. That is the one thing to keep in mind when the destination is also one of the sources: a rung that adds one to a running total will add one per scan, not one per event, unless an edge instruction gates it.

The math instructions in this engine work on 32-bit signed integers by default, with a floating point option, which matches how a DINT and a REAL behave on a real controller.

A rung you can run

A shift total that increments once per part

[object Object]
XIC(Part_Done)ONS(Part_Total_Edge)ADD(Shift_Total,Shift_Total,1)
XIC(Shift_Reset)ONS(Shift_Edge)CLR(Shift_Total)

The one shot is what makes this add one per part instead of one per scan.

Run this rung in the simulator

What it is called on other controllers

PlatformEquivalent
Rockwell (Studio 5000)ADD
Siemens (TIA Portal)ADD
Mitsubishi (GX Works)+ / ADD
CODESYS and IEC 61131-3The + operator

Common mistakes

  • Accumulating without an edge, which counts scans rather than events.
  • Overflowing a 32-bit signed integer on a total that is allowed to run for weeks.

Related instructions

All ladder logic instructions