Mitsubishi Electronics FXCPU Video Game Controller User Manual


 
9 Applied Instructions (Arithmetic and Logical Operation)
9.10 NEG / Negation
194
FXCPU Structured Programming Manual
[Basic & Applied Instruction]
2. Obtaining the absolute value by SUB (subtraction) instruction
Even if NEG instruction (complement operation) 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.
X000
CMP
EN
s1
s2
ENO
d
D10
D20
M10
M10
M11
M12
SUB_E
EN
_IN1
_IN2
ENO
D10
D20
D30
D20
D10
D30
[Structured ladder/FBD]
[ ST ]
CMP(X000,D10, D20, M10);
SUB_E(X000 AND (M10 OR M11), D10, D20, D30);
SUB_E(X000 AND M12, D20, D10, D30);
(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
SUB_E
EN
_IN1
_IN2
ENO
(D 10) +1 = 1
(D 10) = –2
(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
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) = –32,767
(D 10) = –32,767
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 = 32,767
(D 10)+1 = –32,768
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The absolute value can be obtained up to 32,767.