Omron CP1E-N@@D@-@ Computer Hardware User Manual


 
2 Instructions
2-168
CP1E CPU Unit Instructions Reference Manual(W483)
Hint
2’s Complement
A 2’s complement is the value obtained by subtracting each binary digit from 1 and adding one to the
result. For example, the 2’s complement for 1101 is calculated as follows: 1111 (F hexadecimal) –
1101 (D hexadecimal) + 1 (1 hexadecimal) = 0011 (3 hexadecimal). The 2’s complement for 3039
(hexadecimal) is calculated as follows: FFFF (hexadecimal) – 3039 (hexadecimal) + 0001 (hexadeci-
mal) – CFC7 (hexadecimal). Therefore, in case of 4-digit hexadecimal value, the 2’s complement can
be calculated as follows: FFFF (hexadecimal) – a (hexadecimal) + 0001 (hexadecimal) = b (hexadec-
imal). To obtain the true number from the 2’s complement b (hexadecimal): a (hexadecimal) = 10000
(hexadecimal) – b (hexadecimal). For example, to obtain the true number from the 2’s complement
CFC7 (hexadecimal): 10000 (hexadecimal) – CFC7 = 3039.
20F55A10
-
B8A360E3 = -97AE06D3. (Hexadecimal)
In this example, the eight-digit binary value in CIO 121 and CIO 120 is subtracted from the value in CIO
201 and CIO 200, and the result is output in eight-digit binary to D101 and D100. If the result is nega-
tive, the instruction at (2) will be executed, and the actual result will then be output to D101 and D100.
+1
65535
1
65533
65535
Note 1.
2.
3.
4.
Example 1
Signed data Unsigned data
Example 2
Signed data Unsigned data
FFFF Hex
0001 Hex
FFFE Hex
65534 Note 2
FFFD Hex
FFFF Hex
FFFE Hex
65534
Note 4
Carry Flag OFF
Negative Flag ON
Carry Flag OFF
Negative Flag ON
1
2
Note 1
1
3
2 Note 3
Since the Negative Flag is ON, the result (FFFE hex) is
a negative value (2’s complement) and is thus -2.
Since the Carry Flag is OFF, the result (FFFE hex) is
an unsigned positive value of 65534.
Since the Negative Flag is ON, the result (FFFE hex) is
a negative value (2’s complement) and is thus -2.
Since the Carry Flag is ON, the result (FFFE hex) is a
negative value (2’s complement) and becomes -2 when
converted to a true value.
0.00
(1)
P_CY
P_CY
(2)
RSET
21.00
SET
21.00
L
200
120
D100
L
#00000000
D100
D100
”display