DUEMMEGI
MCP 4 – User's manual
Contatto
3.2.7- GOTO
The GOTO instruction causes an unconditional jump to the line of the same script identified by a label. The
label used to identify the destination of a jump must be followed by “:” symbol and placed on an empty line.
The label on the GOTO line, instead, must not be followed by the “:” symbol (see next example).
script
1
trigger
= 1
if
R0
== 1
then
goto
ABC
endif
if
R0
== 2
then
goto
DEF
endif
R10
= 0
exit
ABC:
R10
= 101
exit
DEF:
R10
= 237
exit
endscript
3.2.8- SUBROUTINES and FUNCTIONS
A Subroutine or a Function is a sequence of instructions that can be executed many times by one or more
scripts. The instructions in a subroutine must be surrounded by SUB and ENSUB keywords. All the
subroutines of a program, optionally, may be contained in an single script; in this case, the script containing
the subroutine does not need the TRIGGER instruction (but only if the same script contains only subroutines).
The definition of a subroutine automatically causes the declaration of a
global
variable having the same
name of the subroutine and that can be used to return a value (typically the result of the function).
To “call” a subroutine the CALL instruction can be used, or the function can called in a direct mode. The
following rule is always true:
Use CALL if the subroutine, after the calling, does not return any value
Call directly the function if, after the calling, it must return a value
At every calling of a Subroutine or Function,
one or more parameters can be passed as inputs
(both
variables and constants), specifying them inside round brackets. The variable parameters
can be passed as
reference or as value
. The difference among the two cases is the following:
Parameters passed as reference
: the
Word address
of the parameter (input, output, register, etc.) will
be copied to the related parameter of the subroutine and it will be used as
pointer
inside the subroutine
itself. In this way, the parameter passed to the subroutine
can be both read and modified
by the
subroutine
Parameters passed as value
:
the value of the parameter
(input, output, register, constant, etc.) will be
copied to the related parameter of the subroutine and it will be used as
variable
inside the subroutine
itself. In this way, the parameter passed to the subroutine
can be read but cannot be modified
by the
subroutine. An edit operation on that parameter inside the subroutine will change the value of the local
variable created to receive the parameter but it will not change the parameter passed at the calling
DUEMMEGI
s.r.l. - Via Longhena, 4 – 20139 MILANO
Tel. 02/57300377 - Fax 02/55213686 –
www.duemmegi.it
Rel.: 1.2 October 2018
Page 37 of 87