EasyManua.ls Logo

Omron CP - PROGRAMMING MANUAL 05-2007 - Page 388

Omron CP - PROGRAMMING MANUAL 05-2007
1175 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
355
Symbol Math Instructions Section 3-10
Examples If the result of the subtraction is a negative number (Mi<Su or Mi+1, Mi
<Su+1, Su), the result is output as the 2’s complement and the Carry Flag
(CY) will turn ON to indicate that the result of the subtraction is negative. To
convert the 2’s complement to the true number, an instruction which subtracts
the result from 0 is necessary using the Carry Flag (CY) as an execution con-
dition.
Note 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 cal-
culated as follows: 1111 (F hexadecimal) – 1101 (D hexadecimal) + 1 (1 hexa-
decimal) = 0011 (3 hexadecimal). The 2’s complement for 3039 (hexadecimal)
is calculated as follows: FFFF (hexadecimal) – 3039 (hexadecimal) + 0001
(hexadecimal) – CFC7 (hexadecimal). Therefore, in case of 4-digit hexadeci-
mal value, the 2’s complement can be calculated as follows: FFFF (hexadeci-
mal) – a (hexadecimal) + 0001 (hexadecimal) = b (hexadecimal). To obtain the
true number from the 2’s complement b (hexadecimal): a (hexadecimal) =
10000 (hexadecimal) – b (hexadecimal). For example, to obtain the true num-
ber from the 2’s complement CFC7 (hexadecimal): 10000 (hexadecimal) –
CFC7 (hexadecimal) = 3039 (hexadecimal).
Program Example 20F55A10 – B8A360E3 = –97AE06D3.
In this example, the eight-digit binary value in CIO 211 and CIO 210 is sub-
tracted from the value in CIO 201 and CIO 200, and the result is output in
eight-digit binary to CIO 301 and CIO 300. If the result is negative, the instruc-
tion at (2) will be executed, and the actual result will then be output to CIO 301
and CIO 300.
1
+1
)
65535
1
)
)
3
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
2 Note 1
65534 Note 2
FFFD Hex
FFFF Hex
FFFE Hex
2 Note 3 65534 Note 4
Carry Flag OFF
Negative Flag ON
Carry Flag OFF
Negative Flag ON
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.

Table of Contents

Related product manuals