Passing information with arguments

A way to pass information to internal or external subroutines, or functions, is through arguments. When calling a subroutine, you can pass up to 20 arguments separated by commas on the CALL instruction as follows:
CALL subroutine_name argument1, argument2, argument3,…
In a function call, you can pass up to 20 arguments separated by commas.
function(argument1,argument2,argument3,…)

Using the ARG instruction

A subroutine or function can receive the arguments with the ARG instruction. In the ARG instruction, commas also separate arguments.
ARG arg1, arg2, arg3, …

The names of the arguments that are passed do not have to be the same as those on the ARG instruction because information is passed by position rather than by argument name. The first argument sent is the first argument received and so forth. You can also set up a template in the CALL instruction or function call. The language processor then uses this template in the corresponding ARG instruction. For information about parsing with templates, see Parsing data.

In the following example, the main routine sends information to a subroutine that computes the perimeter of a rectangle. The subroutine returns a value in the variable perim by specifying the value in the RETURN instruction. The main program receives the value in the special variable RESULT .
Figure 1. Example of Passing Arguments on the CALL Instruction. This program receives, as arguments, the length and width of a rectangle and passes that information to an internal subroutine. The subroutine calculates the perimeter of the rectangle.
dfhrx009
The next example is the same except it uses ARG in a function instead of a subroutine.
Figure 2. Example of Passing Arguments on the Call to an Internal Routine. This program receives, as arguments, the length and width of a rectangle and passes that information to an internal function called “perimeter”. The function then calculates the perimeter of the rectangle.
dfhrx012

In the two preceding examples, notice the positional relationships between long and length , and wide and width . Also notice how information is received from variable perim. Both programs include perim on a RETURN instruction. For the program with a subroutine, the language processor assigns the value in perim to the special variable RESULT. For the program using a function, the language processor replaces the function call perimeter(long,wide) with the value in perim.

Using the ARG built-in function

Another way for a subroutine or function to receive arguments is with the ARG built-in function. This function returns the value of a particular argument. A number represents the argument position.

For instance, in the previous example, instead of the ARG instruction:
ARG length, width
you can use the ARG function as follows:
length = ARG(1) /* puts the first argument into length */
width = ARG(2)  /* puts the second argument into width */

For more information about the ARG function see ARG.