Bird
Raised Fist0
PLC Programmingscripting~10 mins

Math instructions (ADD, SUB, MUL, DIV) in PLC Programming - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Math instructions (ADD, SUB, MUL, DIV)
Start
↓
Read Inputs
↓
Select Operation
↓
Perform Calculation
↓
Store Result
↓
End
The PLC reads inputs, selects the math operation (add, subtract, multiply, divide), performs it, and stores the result.
Execution Sample
PLC Programming
ADD 5, 3 -> Result
SUB 10, 4 -> Result
MUL 2, 6 -> Result
DIV 12, 3 -> Result
Perform addition, subtraction, multiplication, and division on given numbers and store the result.
Execution Table
StepInstructionOperandsCalculationResult
1ADD5, 35 + 38
2SUB10, 410 - 46
3MUL2, 62 * 612
4DIV12, 312 / 34
5DIV12, 012 / 0Error: Division by zero
💡 Execution stops after division by zero error to prevent invalid operation.
Variable Tracker
VariableStartAfter ADDAfter SUBAfter MULAfter DIV
Resultundefined86124
Key Moments - 3 Insights
What happens if we try to divide by zero?
As shown in execution_table row 5, division by zero causes an error and stops execution to avoid invalid results.
Does the result variable change after each instruction?
Yes, after each math instruction, the Result variable updates with the new calculation as seen in variable_tracker.
Are the operands always numbers?
Yes, math instructions require numeric operands to perform calculations, as shown in the execution_table operands column.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the Result after the SUB instruction?
A6
B7
C4
D8
💡 Hint
Check the Result column in execution_table row 2 for SUB instruction.
At which step does the division by zero error occur?
AStep 3
BStep 5
CStep 4
DStep 2
💡 Hint
Look at the Instruction and Calculation columns in execution_table for division by zero.
If we change the MUL operands to 3 and 4, what would be the new Result at step 3?
A7
B10
C14
D12
💡 Hint
Multiply 3 by 4 and check the Result column for step 3 in execution_table.
Concept Snapshot
Math instructions in PLC:
- ADD: adds two numbers
- SUB: subtracts second from first
- MUL: multiplies two numbers
- DIV: divides first by second (no zero divisor)
- Result stores output after each operation
Full Transcript
This visual execution shows how PLC math instructions ADD, SUB, MUL, and DIV work step-by-step. The PLC reads two numbers, performs the selected operation, and stores the result. The execution table traces each step with operands, calculation, and result. Division by zero causes an error and stops execution. The variable tracker shows how the Result changes after each instruction. Key moments clarify common confusions like division by zero and variable updates. The quiz tests understanding by referencing the execution visuals.

Practice

(1/5)
1. What does the ADD instruction do in PLC programming?
easy
A. It multiplies two numbers.
B. It subtracts one number from another.
C. It adds two numbers and stores the result.
D. It divides one number by another.

Solution

  1. Step 1: Understand the ADD instruction

    The ADD instruction takes two input values and calculates their sum.
  2. Step 2: Identify the result storage

    The result of the addition is stored in a destination variable or register.
  3. Final Answer:

    It adds two numbers and stores the result. -> Option C
  4. Quick Check:

    ADD = sum [OK]
Hint: ADD means sum two values and save result [OK]
Common Mistakes:
  • Confusing ADD with SUB
  • Thinking ADD multiplies
  • Assuming ADD divides
2. Which of the following is the correct syntax for a SUB instruction in PLC?
easy
A. SUB source1, source2, destination
B. SUB destination, source1, source2
C. SUB source1; source2; destination
D. SUB(source1, source2, destination)

Solution

  1. Step 1: Recall the standard syntax format

    The SUB instruction syntax is: SUB source1, source2, destination.
  2. Step 2: Match options with syntax

    SUB source1, source2, destination matches the correct order and separators (commas).
  3. Final Answer:

    SUB source1, source2, destination -> Option A
  4. Quick Check:

    SUB syntax uses commas and order: source1, source2, destination [OK]
Hint: Syntax uses commas: SUB source1, source2, destination [OK]
Common Mistakes:
  • Swapping destination and sources
  • Using semicolons instead of commas
  • Adding parentheses incorrectly
3. Given the following PLC instructions:
ADD 5, 3, D1
MUL D1, 2, D2
SUB D2, 4, D3
DIV D3, 2, D4

What is the final value stored in D4?
medium
A. 4
B. 6
C. 2
D. 1

Solution

  1. Step 1: Calculate ADD and MUL results

    ADD 5 + 3 = 8 stored in D1; MUL 8 * 2 = 16 stored in D2.
  2. Step 2: Calculate SUB and DIV results

    SUB 16 - 4 = 12 stored in D3; DIV 12 / 2 = 6 stored in D4.
  3. Final Answer:

    6 -> Option B
  4. Quick Check:

    5+3=8, 8*2=16, 16-4=12, 12/2=6 [OK]
Hint: Calculate step-by-step and store intermediate results [OK]
Common Mistakes:
  • Mixing order of operations
  • Forgetting to store intermediate results
  • Dividing before subtracting
4. Identify the error in this PLC math instruction:
DIV 10, 0, D1
medium
A. Incorrect syntax for DIV instruction.
B. Operands must be swapped.
C. Destination variable missing.
D. Division by zero error.

Solution

  1. Step 1: Analyze the DIV instruction inputs

    The instruction tries to divide 10 by 0, which is mathematically undefined.
  2. Step 2: Understand PLC behavior on division by zero

    Most PLCs will raise an error or fault when dividing by zero.
  3. Final Answer:

    Division by zero error. -> Option D
  4. Quick Check:

    DIV by zero causes error [OK]
Hint: Never divide by zero in PLC math instructions [OK]
Common Mistakes:
  • Ignoring zero divisor
  • Assuming syntax error instead
  • Swapping operands incorrectly
5. You want to calculate the average of three sensor readings stored in S1, S2, and S3 using PLC math instructions. Which sequence correctly computes the average and stores it in AVG?
hard
A. ADD S1, S2, T1 ADD T1, S3, T2 DIV T2, 3, AVG
B. ADD S1, S2, T1 DIV T1, 3, T2 ADD T2, S3, AVG
C. DIV S1, 3, T1 DIV S2, 3, T2 DIV S3, 3, T3 ADD T1, T2, T4 ADD T4, T3, AVG
D. SUB S1, S2, T1 ADD T1, S3, T2 DIV T2, 3, AVG

Solution

  1. Step 1: Sum the three sensor readings

    First ADD S1 and S2 into T1, then ADD T1 and S3 into T2 to get total sum.
  2. Step 2: Divide the total sum by 3

    Use DIV to divide T2 by 3 and store the result in AVG, which gives the average.
  3. Final Answer:

    ADD S1, S2, T1 ADD T1, S3, T2 DIV T2, 3, AVG -> Option A
  4. Quick Check:

    Sum all then divide by count = average [OK]
Hint: Sum all values first, then divide by count [OK]
Common Mistakes:
  • Dividing before summing
  • Using SUB instead of ADD
  • Adding after dividing only two values
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard