6-92
6.3 Data Conversion Instructions
6.3.11 Two’s complement of 16-/32-bit BIN data (sign inversion)
NEG, DNEG
DNEG(P)
(1) Inverts the sign of the 32-bit device specified for
and stores the result to the device
specified for
.
(2) This instruction is used when inverting positive and negative signs.
O
p
erat
i
on
E
rror
No operation error occurs in the execution of the NEG(P) and DNEG(P) instructions.
Program
E
xam
pl
e
In the following program, the value in Var_D20 is subtracted from the value in Var_D10 when
X0A turns ON, and if the result is negative, the absolute value is defined.
[Structured ladder]
[ST]
IF X0A THEN
OUT(Var_D10<Var_D20,M3);
Var_D10:=Var_D10-Var_D20;
NEGP(M3,Var_D10);
END_IF;
d
d
3
2
b
it
b
3
1
1
Be
f
ore
execution
1
1
1
1
1
1
0
1
0
0
1
0
0
b
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
0
1
0
0
1
0
0
1
b
3
1
0
0
0
1
1
1
0
b
0
Sign
conversion -
A
f
ter
execution
0
0
0
0
0
1
0
d
d
-
21
84
6
0
21
84
6
0
When the value in
Var_D20 is larger
than the value in
Var_D10, M3 turns
ON.
When M3 is ON, the
absolute value
(two’s complement)
is obtained.
The value in Var_D20
is subtracted from the
value in Var_D10.
1
2
3
...
...
...
Summary of Contents for MELSEC Q Series
Page 1: ...Structured Programming Manual Mitsubishi Programmable Controller QCPU Common Instructions ...
Page 2: ......
Page 14: ...A 12 MEMO ...
Page 340: ...6 178 MEMO MTR ...
Page 708: ...7 368 MEMO ...
Page 776: ...8 68 MEMO ...
Page 796: ...9 20 MEMO ...
Page 804: ...App 8 MEMO ...
Page 812: ...Index 8 MEMO ...
Page 815: ......