Math (output instruction)
MUL: Multiply
Writes A times B into the destination.
Also called: times, product.
MUL(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
MUL exists mostly to scale. A raw analog value arrives as a count from the card, 0 to 27648 on a Siemens input or 0 to 32767 on many others, and it has to become something a person can read: percent, litres, degrees, bar.
The rule that makes scaling work with whole numbers is to multiply before you divide. Raw times 100 divided by 27648 keeps the resolution; raw divided by 27648 times 100 throws it all away first, because the division truncates to zero for every raw value below full scale, and the answer is 0 or 100 and nothing in between. This is the single most common integer maths bug in a PLC program, and it looks like a broken transmitter.
The other direction matters too: multiply two large numbers before dividing and the intermediate result can run past what 32 bits can hold. Scaling factors are usually small enough that this is safe, but it is worth a thought whenever both operands are large.
A rung you can run
Raw counts to percent, in the order that works
MUL(Level_Scaled,Level_Raw,100)
DIV(Level_Percent,Level_Scaled,27648)
GEQ(Level_Percent,90)OTE(High_Level_Alarm)Set Level_Raw to 13824, which is half of full scale, and Level_Percent reads 50. Now swap the two rungs so the divide happens first: the same input gives 0, because 13824 divided by 27648 is 0 once the fraction is thrown away. Same numbers, same instructions, wrong order.
Run this rung in the simulatorWhat it is called on other controllers
| Platform | Equivalent |
|---|---|
| Rockwell (Studio 5000) | MUL |
| Siemens (TIA Portal) | MUL |
| Mitsubishi (GX Works) | The multiply instruction, written as * |
| CODESYS and IEC 61131-3 | MUL, or * in structured text |
Common mistakes
- Dividing before multiplying. With whole numbers the division truncates first and the resolution is gone for good. Always multiply first.
- Forgetting the intermediate value has to fit. A raw count multiplied by a large factor can overflow before the divide brings it back down. Switch the instruction to floating point, or scale in a different order.
Practise it
Interactive exercises that use MUL. Each one checks your ladder against a real scan.
