Elmo HARSFEN0602 Network Hardware User Manual


 
HARSFEN0602
The goto command may be specified only for destinations within the present function scope.
It is not possible to jump to labels that are inside another function.
The jump to the global label from within some function is illegal.
Example:
**Working code
if (PX>1000) **Condition for jump
goto##LABEL1; **Go to LABEL1 if the condition is true
else **Return axis to origin
goto##LABEL2; **Go to LABEL2 if the condition is false
end
… **Working code
##LABEL1; LABEL1 declaration
…. **Working code
##LABEL2; LABEL2 declaration
… **Working code
5.6.7 Functions and The Call Stack
A function is a piece of code that may be called from anywhere in the program. After the
function is executed, the program resumes from the line just after the function call.
Example:
function JustSo ; **function prototype
JV=1000
JustSo() **function call
BG
function JustSo **function definition
IA[0]=1; **function body
return **function end
The above code will execute the sequence
JV=1000;IA[0]=1;BG;
After executing JV=1000, the program jumps to the subroutine JustSo. Before doing so, it stores its return
address. The return address is the place in the code where execution is to resume after the routine is done. In
this example, the return address is the line number of the instruction BG, which is just after the subroutine
call.
The return command instructs the program to resume from the stored return address. After the execution is
resumed at the return address, the return address is no longer required, and it is not stored any more.
Functions may call each other – in fact, they may even call themselves. The return addresses for nested
function calls are stored in a call stack, as shown in the example below.