User's Manual

PMAC User Manual
Writing a PLC Program 241
Valid Operators
All of the mathematical operators (+, -, *, /, %) and bit-by-bit boolean operators (&, |, ^) that can be
used in floating-point operations in uncompiled PMAC programs can also be used in integer operations in
compiled PLCs. The priorities of these operations are the same as for the floating-point operations.
Integer Division
The result of the integer divide is rounded toward the nearest integer, unlike the integer divide in the PCs
Intel 80x86, in which it is truncated toward zero. In the case where the fraction is exactly 0.5, it will
round to the next more positive integer (e.g. -7.5 to -7, and 7.5 to 8 ). In PMAC floating-point operations,
all intermediate values have floating-point resolution and range; if the final value is stored in an integer
register as an I- or M-variable; the rounding rules above apply for this final value.
The following table illustrates the effect of integer division round off:
Integer Division Round-Off Effect
Platform Statement Resulting value
PC
x=10*2/3
6
PMAC
L1=10*2/3
7
PMAC
M1=10*2/3
7
PC
x=10*(2/3)
0
PMAC
L1=10*(2/3)
10
PMAC
M1=10*(2/3)
7
Bit Inversion
The logical NOT operation to invert bits can be executed by operating on the quantity with the ^
exclusive-or operator and a constant value that contains all bits = 1. A single bit L-variable can be
toggled with ^ 1 (for example, L1=L1^1). All bits of a 24-bit L-variable can be changed with ^$FFFFFF
(for example L356=L355^$FFFFFF).
No Functions
It is not acceptable to use any functions in integer variable value assignment statements (e.g.
L1=SIN(L2)).
Intermediate Values
All intermediate values of these integer calculations are signed 24-bit values. Make sure that no
intermediate value in the calculations goes outside of this range. For example, the statement:
L500=-1000000 20000000/4000000
would not execute properly because the product of the first two values is more than 24 bits in length.
The resulting value of the calculation in a variable value assignment statement must be written to an L-
variable. This variable may be less than 24 bits wide. For an L-variable N bits in length, only the low N
bits of the calculated value are written to the register; the rest of the bits are lost. These N bits do not
have to be lowest bits in the register.
For example, with the definition L102->Y:$C003,8,16,S (DAC1 register), in the high 16 bits of a
24-bit word, the statement L102=1000 shifts the value automatically to start at bit 8 in Y:$C003.
Examples:
Examples of legal integer statements:
L100=1
L0=L1-L2*L3+(L4/1024)
L5=L5%1000
L6=L1^$FF