138
●
JS
DMC-40x0 Command Reference
JS
FUNCTION:
Jump to Subroutine, push onto stack
DESCRIPTION:
The JS command will change the sequential order of execution of commands in a program. If the
jump is taken, program execution will continue at the line specified by the destination
parameter, which can be either a line number or label. The line number of the JS command is
saved and after the next EN command is encountered (End of subroutine), program execution
will continue with the instruction following the JS command. There can be a JS command
within a subroutine, up to 16 deep.
Multiple conditions can be used in a single jump statement. The conditional statements are
combined in pairs using the operands “&” and “|”. The “&” operand between any two
conditions, requires that both statements must be true for the combined statement to be true.
The “|” operand between any two conditions, requires that only one statement be true for the
combined statement to be true. Note: Each condition must be placed in parenthesis for proper
evaluation by the controller.
A jump is taken if the specified condition is true. Conditions are tested with logical operators.
The logical operators are:
< less than or equal to
<= less than or equal to
> greater than
>= greater than or equal to
= equal to
<> not equal
Passing Values on the Stack
Note:
Passing values on the stack is
advanced
DMC programming, and is recommended for
experienced DMC programmers familiar with the concept of passing arguments by value and by
reference.
Up to 8 parameters can be passed on the subroutine stack. One value can be returned from a
subroutine. More returns are possible with pass by reference and array passing.
Using subroutine stacks and passing parameters in a subroutine has many advantages including:
1.
Code flexibility/reuse. A single subroutine can be written and called many times and from
various locations in code. The stack “remembers” where to return when completed. This is
opposite from a “blind jump” (JP).
2.
Variable Scope/ Local variables. A subroutine can run with a protected variable space. Local
variables exist only in the extent of the subroutine, and no external thread or stack level can
access local variables. Global variables aren’t needed for counters, indices, and other helper
variables. ^a - ^h must be used for local variables. Regular variable names remain global.
3.
Each thread has its own stack, therefore subroutines are reentrant. In other words, multiple
threads can be running the same subroutine simultaneously at various stack depths.
4.
Support for recursion. Although the subroutine stack is only 16 deep, recursion is possible. A
stack depth of 16 is sufficient for many recursive tasks. E.G. recursing axes, handles, and
thread status.
5.
Parameter passing. A calling command can explicitly specify the inputs to a subroutine. The
subroutine can pass one value back to the calling command. More returns are possible with
pass by reference and array passing.
Constants, Variables, and Arrays may be passed up a subroutine stack.
Summary of Contents for DMC-40x0 Series
Page 2: ......
Page 4: ......
Page 10: ...vi i Table of Contents DMC 40x0 Command Reference This Page is Left Blank Intentionally ...