Appearance
Element Reference: Math, Data and Program Control
Last updated
License feature: Ladder LogicAll the instructions on this page are output instructions that pass power through unchanged: they do their work only on a scan when power in is true, and they never make a rung false. Put the conditions before them.
Math
| Mnemonic | Name | Operands | Destination = |
|---|---|---|---|
| ADD | Add | Source A, Source B, Destination | A + B |
| SUB | Subtract | Source A, Source B, Destination | A − B |
| MUL | Multiply | Source A, Source B, Destination | A × B |
| DIV | Divide | Source A, Source B, Destination | A ÷ B, or 0 if B is 0 (no fault) |
| MOD | Modulo | Source A, Source B, Destination | Remainder of A ÷ B, or 0 if B is 0 |
| SQR | Square Root | Source A, Destination | √A (a negative A gives 0 in an N or F tag) |
| NEG | Negate | Source A, Destination | −A |
| ABS | Absolute Value | Source A, Destination | A without its sign |
The result is a decimal number; an N destination rounds it (7 ÷ 2 → 4). These run on every scan with power in: an ADD with an XIC in front adds on every scan the input is on. To add once per event, use an OSR.
CPT — Compute
| Operand | Notes |
|---|---|
| Expression | Arithmetic, e.g. {3:Line1/Speed} * 60 / 1000 (placeholder e.g. {1:Tag/Path} * 2 + 10) |
| Destination | Where the result goes |
- Refer to a device tag as
{deviceId:tagPath}. The device id is the number shown as Device #3 when you browse a tag on another element. - Only numbers, spaces and
+ - * / % ( ) . < > = ! & | ^ ~ ? :andeare allowed after tag substitution. No function names (nosqrt), and Task/Program Tag addresses can't be used. - A comparison result (
{3:Temp} > 80) is true/false, not a number, and is not written. - An invalid expression leaves the Destination unchanged, with no error.
- Tags in the expression are read at the start of the scan, like every other operand. A negative value works anywhere, including after a minus:
100 - {3:Offset}with Offset = -5 gives 105.
SCP — Scale with Parameters
| Operand | Default |
|---|---|
| Input | — |
| Input Min / Input Max | 0 / 100 |
| Output Min / Output Max | 0 / 100 |
| Destination | — |
Destination = (Input − Input Min) × (Output Max − Output Min) ÷ (Input Max − Input Min) + Output Min. The four limits are fixed numbers. The result is not clamped: an input outside the range extrapolates. If Input Min equals Input Max, the result is Output Min.
Example: a 4–20 mA pressure transmitter read as raw counts 6400–32000 for 0–10 bar → Input Min 6400, Input Max 32000, Output Min 0, Output Max 10, Destination F_PressureBar.
Data Move
| Mnemonic | Name | Operands | Behavior |
|---|---|---|---|
| MOV | Move | Source, Destination | Copies Source to Destination as a number (text becomes 0 — use DTOS/STOD for text) |
| MVM | Masked Move | Source, Mask, Destination | Destination = (Source AND Mask) OR (Destination AND NOT Mask), on whole numbers. Set the Mask explicitly — an unset mask is 0 and nothing changes |
| COP | Copy | Source, Destination, Length | Copies Length consecutive elements: Source N7:0 to Destination N7:10 with Length 3 copies N7:0–2 to N7:10–12. A named device tag Buffer counts as Buffer, Buffer[1], Buffer[2]… |
| FLL | Fill | Source, Destination, Length | Writes the Source value into Length consecutive Destination elements |
| CLR | Clear | Destination | Writes 0 |
Bitwise
Values are rounded to whole numbers and treated as 32-bit integers.
| Mnemonic | Name | Operands | Destination = |
|---|---|---|---|
| AND | Bitwise AND | Source A, Source B, Destination | A AND B |
| OR | Bitwise OR | Source A, Source B, Destination | A OR B |
| XOR | Bitwise XOR | Source A, Source B, Destination | A XOR B |
| NOT | Bitwise NOT | Source A, Destination | NOT A (NOT 0 = −1) |
| BSL | Bit Shift Left | Source A, Source B, Destination | A shifted left by B bits (B 0–31) |
| BSR | Bit Shift Right | Source A, Source B, Destination | A shifted right by B bits, filling with 0 |
BSL and BSR shift a number; they are not the RSLogix bit-array shift registers with a bit input.
Conversion
| Mnemonic | Name | Operands | Behavior |
|---|---|---|---|
| TOD | To BCD | Source, Destination | 1234 → 0x1234 (4660). The sign is dropped |
| FRD | From BCD | Source, Destination | 0x1234 → 1234 |
| DTOS | DINT to String | Source, Destination | Whole number to text, e.g. into ST_Batch |
| STOD | String to DINT | Source, Destination | Text to whole number ("42 kg" → 42, non-numbers → 0) |
Program Control
| Mnemonic | Name | Setting | Behavior |
|---|---|---|---|
| JSR | Jump to Subroutine | Routine — Select a routine… from this program | When the rung has power at the JSR, the routine runs after this rung finishes. An SFC chart can be called too |
| SBR | Subroutine | — | Marker only; does nothing |
| RET | Return | — | With power, the current routine stops after this rung |
| JMP | Jump to Label | Label (e.g. loop_start) | With power, the scan continues at the rung containing the matching LBL in the same routine. A missing label does nothing |
| LBL | Label | Label | Marks a jump target; does nothing |
| FOR | For Loop | Index Tag, Initial, Terminal, Step | With power: sets Index to Initial and runs the rungs down to the matching NXT, then adds Step and repeats while Index ≤ Terminal (≥ for a negative Step). Without power, or if Initial is already past Terminal, those rungs are skipped |
| NXT | Next | — | Closes the FOR loop above it. FOR/NXT pairs nest like brackets |
| MCR | Master Control Reset | — | See below |
Note: A loop that runs more than 10,000 times in one scan faults the task (FOR loop in "…" ran more than 10000 times in one scan). A Step of 0 skips the loop.
Warning: A JMP to an earlier rung repeats those rungs within the same scan. If the jump rung stays true, the scan never ends. A 1-second watchdog catches this: the scan is cut off, the task faults with Watchdog: the scan was still running after 1000 ms, at rung N of "…" and stops itself, and the appliance stays responsive. Only jump forward, or make sure the condition goes false inside the loop, so scans stay fast.
Each routine has its own labels, so JMP always finds the right target in the routine it runs in, including after a JSR returns to the caller.
MCR fences off a zone with a pair of MCR elements. The first one the scan reaches is the fence: if its own rung is false, every OTE between it and the second MCR is forced off (writes 0) and passes no power, for that scan. If the fence rung is true, the zone runs normally. The second MCR always closes the zone, whatever its own rung does — it isn't itself conditional, the same as an Allen-Bradley End MCR. OTL, OTU, timers and math inside the zone run normally either way. An MCR with no matching second one stays open for the rest of the scan.