3. Instructions
564
CS/CJ/NSJ Series Instructions Reference Manual (W474)
Flags
Function
SNUM(638) counts the number of data words in the specified stack from the beginning of the data
region at TB+4 to the address before the one indicated by the stack pointer (TB+3 and TB+2).
SNUM(638) does not change the data in the stack or the stack pointer.
The stack must be defined in advance with SSET(630).
Hint
As an example, this instruction is used to count the number of work pieces currently on a conveyor belt.
Example Programming
When CIO 0.00 is ON in the following example, SNUM(638) counts the number of words from the
beginning of the data region at D4 to the stack pointer position - 1 (D6) and outputs the result to D300.
(In this case, the stack pointer indicates D7.)
Name Label Operation
Error Flag P_ER OFF
Equal Flag P_EQ • ON if the number of words of data in the stack (the value output to D) is 0.
• OFF in all other cases.
A
TB
TB+1
TB+2
TB+3
TB+4
N
m
n
D
n
m
Counts the number of words
(N) from the address of the
beginning of the stack (TB+4)
to the pointer position −1.
PLC memory
address
Last word
in stack
Stack
Pointer
SNUM
D0
D300
0.00
D0
D1
D2
D3
D4
D5
D6
D7
D8
D9
D:D300
3Hex
PLC memory
address
Stack
pointer
Stack pointer
Last word
in stack
PLC memory address of
last word in the stack
Counts number of data
words. (3 in this example.)