User Tools

Site Tools


en-us_products:mpino_studio2:box_functions:arithmetic

This is an old revision of the document!


MPINO STUDIO 2 Phase 4-4 · Arithmetic Box Functions

These commands store arithmetic, increment, scaling, and floating-point results.

These commands store arithmetic, increment, scaling, and floating-point results.

This ladder screen adds two WORD values with ADD.

This ladder screen adds two WORD values with ADD.

Box-function inputs and example results

1. Common Rules

The first two values are sources and the final address stores the result. INC and DEC change the target itself by one. The data format and range follow the memory rules in Phase 2.

2. ADD, SUB, MUL, DIV, and MOD

ADD

Add

Adds two values and stores the result in the destination.

Syntax: ADD D0 D1 D2

Run condition Before Command entered Expected result
Left condition ON D0=12, D1=5 ADD D0 D1 D2 D2=17

SUB

Subtract

Subtracts the second value from the first and stores the result in the destination.

Syntax: SUB D0 D1 D2

Run condition Before Command entered Expected result
Left condition ON D0=12, D1=5 SUB D0 D1 D2 D2=7

MUL

Multiply

Multiplies two values and stores the result in the destination.

Syntax: MUL D0 D1 D2

Run condition Before Command entered Expected result
Left condition ON D0=12, D1=5 MUL D0 D1 D2 D2=60

DIV

Divide

Divides the first value by the second and stores the quotient. With integer operands, the fractional part is discarded.

Syntax: DIV D0 D1 D2

Run condition Before Command entered Expected result
Left condition ON D0=12, D1=5 DIV D0 D1 D2 D2=2

MOD

Modulo

Divides the first value by the second and stores the remainder.

Syntax: MOD D0 D1 D2

Run condition Before Command entered Expected result
Left condition ON D0=12, D1=5 MOD D0 D1 D2 D2=2

3. INC and DEC

INC

Increment

Increments the destination by one and stores it back at the same address.

Syntax: INC D0

Arguments

  • 1st = D: target address (stores the previous value +1 back to the same address)
Run condition Before Command entered Expected result
Left condition ON D0=7 INC D0 D0=8

DEC

Decrement

Decrements the destination by one and stores it back at the same address.

Syntax: DEC D0

Arguments

  • 1st = D: target address (stores the previous value −1 back to the same address)
Run condition Before Command entered Expected result
Left condition ON D0=7 DEC D0 D0=6

4. SCALE

Scale (Linear Interpolation)

Linearly maps an integer from an input range to an integer output range. Values outside the input range are limited to the nearest boundary; equal IN_MIN and IN_MAX stores OUT_MIN.

Syntax: SCALE D0 0 1023 R0 0 100

Arguments

  • 1st = input: address or constant to convert
  • 2nd = input minimum
  • 3rd = input maximum
  • 4th = destination: address that stores the output
  • 5th = output minimum
  • 6th = output maximum
Run condition Before Command entered Expected result
Left condition ON D0=1023 SCALE D0 0 1023 R0 0 100 R0=100.0

5. FLOOR and SQRT

FLOOR

Floor

Stores the greatest integer that is not larger than the source. For example, 12.8 becomes 12 and -1.2 becomes -2.

Syntax: FLOOR R0 R1

Arguments

  • 1st = source: address or constant to round down
  • 2nd = destination: address that stores the result
Run condition Before Command entered Expected result
Left condition ON R0=12.8 FLOOR R0 R1 R1=12.0

SQRT

Square Root

Stores the square root of the source. Use R memory as the destination when the result must retain its fractional part.

Syntax: SQRT D0 R0

Arguments

  • 1st = source: nonnegative address or constant
  • 2nd = destination: address that stores the result
Run condition Before Command entered Expected result
Left condition ON D0=81 SQRT D0 R0 R0=9.0

6. Troubleshooting

Symptom What to check
DIV or MOD produces no result. Check whether the second source value is zero.
The SCALE result stays at one boundary. Check the input value and the order and range of IN_MIN and IN_MAX.
en-us_products/mpino_studio2/box_functions/arithmetic.1788947072.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki