Mitsubishi Electronics FX3S User Manual
291
FX
3S
/FX
3G
/FX
3GC
/FX
3U
/FX
3UC
Series
Programming Manual - Basic & Applied Instruction Edition
10 Arithmetic and Logical Operation (
+, −, ×, ÷) – FNC 20 to FNC 29
10.10 FNC 29 – NEG / Negation
1
Introdu
ction
2
Ov
ervi
ew
ew
3
Instruction
Li
st
4
D
evices
in Det
ai
l
5
Specifi
ed the
De
vice
&
C
onst
ant
ant
6
Bef
ore
ore
Pr
og
ra
mmi
ng
ng
7
Bas
ic
ic
Instruction
8
FN
C00-FN
C00-FN
C0
9
Program Fl
ow
9
FNC
10-FN
C19
Mov
e & Com
e & Com
pare
10
FNC
20-FNC
29
Arith. & Lo
gi
c
Operati
on
Program examples
The program examples below are provided to obtain the absolute value of a negative binary value.
1. Obtaining the absolute value of a negative value using NEG instruction
2. Obtaining the absolute value by SUB (subtraction) instruction
Even if NEG instruction is not used, D30 always stores the absolute value of the difference.
Negative value expression and absolute value (reference)
In PLCs, a negative value is expressed in 2’s complement.
When the most significant bit is "1", it is a negative value, and its absolute value can be obtained by NEG
instruction.
When the most significant bit is "1", it is a negative value, and its absolute value can be obtained by NEG
instruction.
M 0
FNC 29
NEGP
D 10
M8000
FNC 44
BON
D 10
M 0
K 15
RUN monitor
In BON (ON bit check) instruction, M0 turns ON
when the bit 15 (b15 among b0 to b15) of D10 is "1".
NEGP instruction is executed for D10 only when M0
turns ON.
D10
→ D10
X000
M 10
M 11
M 12
FNC 21
SUB
D 10
D 20
D 30
FNC 21
SUB
D 20
D 10
D 30
FNC 10
CMP
D 10
D 20
M 10
(D 10) > (D 20) (D10) = (D 20) (D 10) < (D 20)
M 10 = ON M 11 = ON M 12 = ON
In the case of "D10
≥ D20",
D10
− D20 → D30.
In the case of "D10 < D20",
D20
− D10 → D30.
(D 10) = 2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
(D 10) = 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
(D 10) = 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
(D 10) =
−1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
(D 10) =
−2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
(D 10) =
−32767
(D 10) =
−32768
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
(D 10) + 1 = 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
(D 10) + 1 = 2
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
(D 10) + 1 = 32767
(D 10) + 1 =
−32768
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The absolute value can be obtained up to 32767.
......
......