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
| Name | What it is | Accepts | Default |
|---|---|---|---|
| destination | What the instruction acts on | a register | required |
| a | Value A | a number or a tag | 0 |
| b | Value B | a number or a tag | 1 |
| real | Floating point | true or false | false |
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
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 simulatorWhat it is called on other controllers
| Platform | Equivalent |
|---|---|
| Rockwell (Studio 5000) | ADD |
| Siemens (TIA Portal) | ADD |
| Mitsubishi (GX Works) | + / ADD |
| CODESYS and IEC 61131-3 | The + 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.
