357
SUM, SUMP, DSUM, DSUMP
1
2
3
4
4
6
7
8
7.5
D
ata pr
ocessin
g instru
ctions
7.5.2
S
UM, SUMP, DSUM,
DSUMP
Function
SUM
From the 16-bit data in the device designated by , stores the total number of bits where 1 is set, in the device
designated by .
DSUM
From the 32-bit data in the device designated by , stores the total number of bits where 1 is set, in the device
designated by .
Operation Error
(1) There is no operation error in the SUM(P) or DSUM(P) instruction.
Program Example
(1) The following program stores the number of bits which are ON from X8 to X17 into D0 when X10 is turned ON.
[Ladder Mode]
[List Mode]
[Operation]
(2) The following program stores the number of bits which are ON in D100 and D101 into D0 when X10 is turned ON.
[Ladder Mode]
[List Mode]
S
D
b15
b8
1 1 0 0 1 0 1 1 0 0 1 1 0 0 0 1
b0
b7
b15
b8
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
b0
b7
Total number of bits where 1 is set
Stores the total number of bits where 1 is set in BIN.
(
There are 8 bits where 1 is set in the example.
)
S
D
S
D
S
D
1 0 0 1 1 1 0 0 1 0 1 0 0 1 1 1
b15
b8
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
b0
b7
Total number of bits where 1 is set
Stores the total number of bits where 1 is set in BIN.
(
There are 16 bits where 1 is set in the example.
)
0 0 0 1 0 0 0 0 1 1 1 1 0 1 1 0
b31
b16b15
b0
S
+1
Step
Instruction
Device
X17
0 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1
X8
Stores the total number of bits
where 1 is set at D0.
D0
7
Step
Instruction
Device