• 沒有找到結果。

6.4 ---( JMPN ) Jump-If-Not

7 Integer Math Instructions

7.1 Overview of Integer Math Instructions

Description

Using integer math, you can carry out the following operations with two integer numbers (16 and 32 bits):

• ADD_I Add Integer

• SUB_I Subtract Integer

• MUL_I Multiply Integer

• DIV_I Divide Integer

• ADD_DI Add Double Integer

• SUB_DI Subtract Double Integer

• MUL_DI Multiply Double Integer

• DIV_DI Divide Double Integer

• MOD_DI Return Fraction Double Integer

长沙工控帮教育科技有限公司整理

7.2 Evaluating the Bits of the Status Word with Integer Math Instructions

Description

The integer math instructions affect the following bits in the Status word: CC1 and CC0, OV and OS.

The following tables show the signal state of the bits in the status word for the results of instructions with Integers (16 and 32 bits):

Valid Range for the Result CC 1 CC 0 OV OS

0 (zero) 0 0 0 *

16 bits: -32 768 <= result < 0 (negative number) 32 bits: -2 147 483 648 <=result < 0 (negative number)

0 1 0 *

16 bits: 32 767 >= result > 0 (positive number) 32 bits: 2 147 483 647 >= result > 0 (positive number)

1 0 0 *

* The OS bit is not affected by the result of the instruction.

Invalid Range for the Result A1 A0 OV OS

Underflow (addition) 16 bits: result = -65536 32 bits: result = -4 294 967 296

0 0 1 1

Underflow (multiplication)

16 bits: result < -32 768 (negative number) 32 bits: result < -2 147 483 648 (negative number)

0 1 1 1

Overflow (addition, subtraction)

16 bits: result > 32 767 (positive number) 32 bits: result > 2 147 483 647 (positive number)

0 1 1 1

Overflow (multiplication, division) 16 bits: result > 32 767 (positive number) 32 bits: result > 2 147 483 647 (positive number)

1 0 1 1

Underflow (addition, subtraction)

16 bits: result < -32. 768 (negative number) 32 bits: result < -2 147 483 648 (negative number)

1 0 1 1

Division by 0 1 1 1 1

Operation A1 A0 OV OS

+D: result = -4 294 967 296 0 0 1 1

/D or MOD: division by 0 1 1 1 1

长沙工控帮教育科技有限公司整理

7.3 ADD_I Add Integer

Parameter Data Type Memory Area Description

EN BOOL I, Q, M, L, D Enable input

ENO BOOL I, Q, M, L, D Enable output

IN1 INT I, Q, M, L, D

or constant

First value for addition

IN2 INT I, Q, M, L, D

or constant

Second value for addition

OUT INT I, Q, M, L, D Result of addition

Description

ADD_I (Add Integer) is activated by a logic "1" at the Enable (EN) Input. IN1 and IN2 are added and the result can be scanned at OUT. If the result is outside the permissible range for an integer (16-bit), the OV bit and OS bit will be "1" and ENO is logic "0", so that other functions after this math box which are connected by the ENO (cascade arrangement) are not executed.

See also Evaluating the Bits of the Status Word with Integer Math Instructions.

Status word

The ADD_I box is activated if I0.0 = "1". The result of the addition MW0 + MW2 is output to MW10. If the result was outside the permissible range for an integer, the output Q4.0 is set.

长沙工控帮教育科技有限公司整理

7.4 SUB_I Subtract Integer

Parameter Data Type Memory Area Description

EN BOOL I, Q, M, L, D Enable input

ENO BOOL I, Q, M, L, D Enable output

IN1 INT I, Q, M, L, D

or constant

First value for subtraction

IN2 INT I, Q, M, L, D

or constant

Value to subtract

OUT INT I, Q, M, L, D Result of subtraction

Description

SUB_I (Subtract Integer) is activated by a logic "1" at the Enable (EN) Input. IN2 is subtracted from IN1 and the result can be scanned at OUT. If the result is outside the permissible range for an integer (16-bit), the OV bit and OS bit will be "1" and ENO is logic "0", so that other functions after this math box which are connected by the ENO (cascade arrangement) are not executed.

See also Evaluating the Bits of the Status Word with Integer Math Instructions.

Status word

The SUB_I box is activated if I0.0 = "1". The result of the subtraction MW0 - MW2 is output to MW10. If the result was outside the permissible range for an integer or the signal state of I0.0 = 0, the output Q4.0 is set.

长沙工控帮教育科技有限公司整理

7.5 MUL_I Multiply Integer

Parameter Data Type Memory Area Description

EN BOOL I, Q, M, L, D Enable input

ENO BOOL I, Q, M, L, D Enable output

IN1 INT I, Q, M, L, D

or constant

First value for multiplication

IN2 INT I, Q, M, L, D

or constant

Second value for multiplication

OUT INT I, Q, M, L, D Result of multiplication

Description

MUL_I (Multiply Integer) is activated by a logic "1" at the Enable (EN) Input. IN1 and IN2 are multiplied and the result can be scanned at OUT. If the result is outside the permissible range for an integer (16-bit), the OV bit and OS bit will be

"1" and ENO is logic "0", so that other functions after this math box which are connected by the ENO (cascade arrangement) are not executed.

See also Evaluating the Bits of the Status Word with Integer Math Instructions.

Status word

The MUL_I box is activated if I0.0 = "1". The result of the multiplication MW0 x MW2 is output to MD10. If the result was outside the permissible range for an integer, the output Q4.0 is set.

长沙工控帮教育科技有限公司整理

7.6 DIV_I Divide Integer

Parameter Data Type Memory Area Description

EN BOOL I, Q, M, L, D Enable input

DIV_I(Divide Integer) is activated by a logic "1" at the Enable (EN) Input. IN1 is divided by IN2 and the result can be scanned at OUT. If the result is outside the permissible range for an integer (16-bit), the OV bit and OS bit is "1" and ENO is logic "0", so that other functions after this math box which are connected by ENO (cascade arrangement) are not executed.

See also Evaluating the Bits of the Status Word with Integer Math Instructions.

Status word

The DIV_I box is activated if I0.0 = "1". The result of the division MW0 by MW2 is output to MW10. If the result was outside the permissible range for an integer, the output Q4.0 is set.

长沙工控帮教育科技有限公司整理

7.7 ADD_DI Add Double Integer

Parameter Data Type Memory Area Description

EN BOOL I, Q, M, L, D Enable input

ENO BOOL I, Q, M, L, D Enable output

IN1 DINT I, Q, M, L, D

or constant

First value for addition

IN2 DINT I, Q, M, L, D

or constant

Second value for addition

OUT DINT I, Q, M, L, D Result of addition

Description

ADD_DI (Add Double Integer) is activated by a logic "1" at the Enable (EN) Input.

IN1 and IN2 are added and the result can be scanned at OUT. If the result is outside the permissible range for a double integer (32-bit), the OV bit and OS bit will be "1" and ENO is logic "0", so that other functions after this math box which are connected by the ENO (cascade arrangement) are not executed.

See also Evaluating the Bits of the Status Word with Integer Math Instructions.

Status word

The ADD_DI box is activated if I0.0 = "1". The result of the addition MD0 + MD4 is output to MD10. If the result was outside the permissible range for a double integer, the output Q4.0 is set.

长沙工控帮教育科技有限公司整理

7.8 SUB_DI Subtract Double Integer

Parameter Data Type Memory Area Description

EN BOOL I, Q, M, L, D Enable input

ENO BOOL I, Q, M, L, D Enable output

IN1 DINT I, Q, M, L, D

or constant

First value for subtraction

IN2 DINT I, Q, M, L, D

or constant

Value to subtract

OUT DINT I, Q, M, L, D Result of subtraction

Description

SUB_DI (Subtract Double Integer) is activated by a logic "1" at the Enable (EN) Input. IN2 is subtracted from IN1 and the result can be scanned at OUT. If the result is outside the permissible range for a double integer (32-bit), the OV bit and OS bit will be "1" and ENO is logic "0", so that other functions after this math box which are connected by the ENO (cascade arrangement) are not executed.

See also Evaluating the Bits of the Status Word with Integer Math Instructions.

Status word

The SUB_DI box is activated if I0.0 = "1". The result of the subtraction MD0 - MD4 is output to MD10. If the result was outside the permissible range for a double integer, the output Q4.0 is set.

长沙工控帮教育科技有限公司整理

7.9 MUL_DI Multiply Double Integer

Parameter Data Type Memory Area Description

EN BOOL I, Q, M, L, D Enable input

ENO BOOL I, Q, M, L, D Enable output

IN1 DINT I, Q, M, L, D

or constant

First value for multiplication

IN2 DINT I, Q, M, L, D

or constant

Second value for multiplication

OUT DINT I, Q, M, L, D Result of multiplication

Description

MUL_DI (Multiply Double Integer) is activated by a logic "1" at the Enable (EN) Input. IN1 and IN2 are multiplied and the result can be scanned at OUT. If the result is outside the permissible range for a double integer (32-bit), the OV bit and OS bit will be "1" and ENO is logic "0", so that other functions after this math box which are connected by the ENO (cascade arrangement) are not executed.

See also Evaluating the Bits of the Status Word with Integer Math Instructions.

Status word

The MUL_DI box is activated if I0.0 = "1". The result of the multiplication

MD0 x MD4 is output to MD10. If the result was outside the permissible range for a double integer, the output Q4.0 is set.

长沙工控帮教育科技有限公司整理

7.10 DIV_DI Divide Double Integer

Parameter Data Type Memory Area Description

EN BOOL I, Q, M, L, D Enable input

OUT DINT I, Q, M, L, D Whole-number result of division

Description

DIV_DI (Divide Double Integer) is activated by a logic "1" at the Enable (EN) Input.

IN1 is divided by IN2 and the result can be scanned at OUT. The Divide Double Integer element does not produce a remainder. If the result is outside the permissible range for a double integer (32-bit), the OV bit and OS bit is "1" and ENO is logic "0", so that other functions after this math box which are connected by the ENO (cascade arrangement) are not executed.

See also Evaluating the Bits of the Status Word with Integer Math Instructions.

Status word

The DIV_DI box is activated if I0.0 = "1". The result of the division MD0 : MD4 is output to MD10. If the result was outside the permissible range for a double integer, the output Q4.0 is set.

长沙工控帮教育科技有限公司整理

7.11 MOD_DI Return Fraction Double Integer

Parameter Data Type Memory Area Description

EN BOOL I, Q, M, L, D Enable input

OUT DINT I, Q, M, L, D Remainder of division

Description

MOD_DI (Return Fraction Double Integer) is activated by a logic "1" at the Enable (EN) Input. IN1 is divided by IN2 and the fraction can be scanned at OUT. If the result is outside the permissible range for a double integer (32-bit), the OV bit and OS bit is "1" and ENO is logic "0", so that other functions after this math box which are connected by the ENO (cascade arrangement) are not executed.

See also Evaluating the Bits of the Status Word with Integer Math Instructions.

Status word

The DIV_DI box is activated if I0.0 = "1". The remainder of the division MD0:MD4 is output to MD10. If the remainder was outside the permissible range for a double integer, the output Q4.0 is set.

长沙工控帮教育科技有限公司整理

长沙工控帮教育科技有限公司整理