118
4
4 Instructions4.4.2 Logical Operations
◆
Example:
The following example gets the absolute value of the difference in a subtraction:
M10 = ON if D2 > D4; M11 = ON if D2 = D4; M12 = ON if D2 < D4. This ensures that the value in D10 is
positive.
The preceding program is represented as follows:
When bit 15 of D10 is 1 (indicating that the value in D10 is negative), then M10 = ON. Use the NEG
instruction to get the absolute value of D10.
In the preceding examples, D10 = K4 if D2 = K4 and D4 = K8 or D2 = K8 and D4 = K4.
Negative number representation and absolute value:
1) Positive and negative numbers are represented by the leftmost bit content of the register. A positive
number is represented by 0, whereas a negative number is represented by 1.
2) When the highest bit is 1, use the NEG instruction to convert it to an absolute value.
0100000000000000
(D 10)=2
1000000000000000
(D 10)=1
0
000000000000000
(D 10)=0
1111111111111111
(D 10)=-1
0111111111111111
(D 10)=-2
1011111111111111
(D 10)=-3
0011111111111111
(D 10)=-4
1101111111111111
(D 10)=-5
1000000000000000
(D 10)+1=1
0100000000000000
(D 10)+1=2
1100000000000000
(D 10)+1=3
0010000000000000
(D 10)+1=4
1010000000000000
(D 10)+1=5