2-171
2 Instructions
CP1E CPU Unit Instructions Reference Manual(W483)
Symbol Math Instructions
2
–C/–CL
Function
–C
–C(412) subtracts the binary values in Su and CY from Mi, and outputs the result to R. When the result
is negative, it is output to R as a 2’s complement.
–CL
–CL(413) subtracts the binary values in Su and Su+1 and CY from Mi and Mi+1, and outputs the result
to R, R+1. When the result is negative, it is output to R, R+1 as a 2’s complement.
Hint
To clear the Carry Flag (CY), execute the Clear Carry (CLC(041)) instruction.
2’s Complement
A 2’s complement is the value obtained by subtracting each binary digit from 1 and adding one to the
result.
Example: The 2’s complement for the binary number 1101 is as follows:
1111 (F hex) – 1101 (D hex) + 1 (1 hex) = 0011 (3 hex).
Example: The 2’s complement for the 4-digit hexadecimal number 3039 is as follows:
FFFF hex - 3039 hex + 0001 hex = CFC7 hex.
Accordingly, the 2’s complement for the 4-digit hexadecimal value “a” is as follows:
FFFF hex – a hex + 0001 hex = b hex.
And to obtain the true number “a” hex from the 2’s complement “b” hex:
a hex + 10000 hex – b hex.
Example: To obtain the true number from the 2’s complement CFC& hex:
10000 hex – CFC7 hex = 3039 hex.
Sample program
If the result of the subtraction is a negative number (Mi<Su or Mi+1, Mi <Su+1, Su), the result is output
as a 2’s complement. The Carry Flag (CY) will turn ON. To convert the 2’s complement to the true num-
ber, a program which subtracts the result from 0 is necessary, as an input condition of the Carry Flag
(CY). The Carry Flag turning ON thus indicates that the result of the subtraction is negative.
CY
R
CY
Mi
Su
(Signed binary)
(Signed binary)
(Signed binary)
CY will turn ON
when there is a
borrow.
R+1
CY
R
CY
Mi+1
Su+1
Mi
Su
(Signed binary)
(Signed binary)
(Signed binary)
CY will turn ON
when there is a
borrow.
C
D100
D110
D120
0.00
When CIO 0.00 is ON in the following example, D110 and CY will be
subtracted from D100 as 4-digit signed binary values and the result will
be output to D120.
CL
D100
D110
D120
0.00
When CIO 0.00 is ON in the following example, D111, D110 and CY will be
subtracted from D101 and D100 as 8-digit signed binary values, and the
result will be output to D121 and D120.