Mitsubishi Electronics 13JW55 ユーザーズマニュアル
5 - 55
Project name
QTEST9
Program name
MAIN
5.7.5 Exercise 5 Addition and subtraction instructions
Create a program that:
1) Imports the values specified by the digital switches (X20 to X2F) to D3 and D2
1) Imports the values specified by the digital switches (X20 to X2F) to D3 and D2
(32-bit data) when X0 is turned on, adds them to D1 and D0, and displays the
result on the displays (Y40 to Y5F).
result on the displays (Y40 to Y5F).
2) Imports the values specified by the digital switches (X20 to X2F) to D5 and D4
when X1 is turned on, subtracts them from D1 and D0, and displays the result.
3) When the result is a negative number, Y77 is turned on, the two's complement is
determined from the result to obtain the absolute value, and displayed.
Fill in the blanks in the following.
Then, check the operation using the demonstration machine.
Then, check the operation using the demonstration machine.
X0
0
M1
PLS
D0
D0
1)
D2
K4X20
D2
DBCD
K8Y40
D4
D0
DBIN
D0
K0
D<=
X1
X0
X1
9
17
26
K4X20
DBIN
D4
D0
DCML
D8
D0
K0
D>
30
M1
K1
D+P
D8
D8
DBCD
K8Y40
K0
DMOV
D0
X7
50
Y77
2)
Adds the external
set value to D0.
set value to D0.
Displays the result when
it is a positive number.
it is a positive number.
Subtracts the external
set value from D0.
set value from D0.
When the result is a
negative number, it is
converted into a positive
number and displayed.
(The negative absolute
value is determined.)
negative number, it is
converted into a positive
number and displayed.
(The negative absolute
value is determined.)
Outputs that the number
is negative.
is negative.
Clears D0 and D1.
1)
2)
2)
Reference
M1
K0
D0
D>
D0
D8
DCML
K1
D8
D
+
P
Complement (deny transfer)
The absolute value is determined
by a calculation of two's complement
of D0 and D1 (32-bit data).
by a calculation of two's complement
of D0 and D1 (32-bit data).
1
1
1
0
1
1
0
0
1
0
B31 B30
B18 B17 B16 B15 B14
B2 B1 B0
D1
D0
Before DCML
execution
(negative number)
0
0
0
1
0
0
1
1
0
1
D9
D8
After DCML
execution
0
0
0
1
0
0
1
1
1
0
D9
D8
After D + P execution
(absolute value)
REMARK
The CML instruction inverts the bit pattern of
S
and transfers the data to
D
when the input condition is turned on.
Input condition
D0
D10
CML
D
S