omron — CALL program instruction

CALL program instruction Details The CALL instruction causes execution of the current program to be suspended temporarily. Execution continues at the first step of the indicated new program, which is then considered a subroutine. Execution automatically returns to the current program when a RETURN instruction is executed in the subroutine. Execution continues with the instruction immediately following the CALL instruction. Subroutine arguments can be passed by value or by reference. When an argument is passed by value, a copy of the argument value is passed to the subroutine.

Any changes to the corresponding subroutine argument in the subroutine will not be passed back to the calling routine. Any argument that is specified as an expression (or compound transformation) will be passed by value. When an argument is a (scalar or array) variable, it is passed by reference. That means a pointer to the variable is passed to the subroutine, which then works with exactly the same variable as the calling routine. If the called routine changes the value of the variable, the value is also changed for the calling routine. This can be especially significant, for example, if the same variable is passed as two arguments of a subroutine call.

Then, any change to either of the corresponding subroutine arguments in the subroutine automatically changes the other corresponding subroutine argument. Note that an argument that is passed by reference (because it is a variable) can generally be forced to passage by value. The way that is done depends on the type of the variable, as follows: l For a real variable, passage by value can be forced by enclosing the variable in parentheses: l For a string variable, an empty string ("") can be added to the variable:

CALL prog_a((count)) CALL prog_b($str.var+"") l For a transformation variable (for example, start), an equivalent transformation value can be specified by a compound transformation consisting of the variable and the NULL transformation: CALL prog_c(start:NULL) As stated above, the items in the arg_list must match their corresponding items in the called program. In addition to straightforward matches of scalar to scalar, and arrays of equal numbers of dimensions, there are several situations in which higher dimension arrays can be passed in place of lower dimension arrays. For example, all the following cases are valid: l Array element passed to a scalar:

CALL example(a[1]) ---> .PROGRAM example(b) eV+Language Reference Guide, v2.x, 18319-000 Rev A Page 110