Omron SYSMAC CV500-BSC11 Operation Manual page 71

Basic units
Table of Contents

Advertisement

BASIC Syntax and Operations
RETURN Command Ending
Subroutine
Calling Subroutines
Main program
GOSUB
As shown above, by using subroutines the program can be divided into several
modules so that it can be easy to see and develop and so that the same process
can be executed from different locations.
Program
Task 1
Operation
processing
Task 2
Operation
processing
Task 3
Operation
processing
When a subroutine is called, a return address is stored in a memory area so that
the program execution can be returned to the main routine after the subroutine
has been executed. This memory area is called a stack. To return the execution
from a subroutine to the main routine, the return address is restored from the
stack by the RETURN command.
Subroutine
Return address
Only one level can be restored by the RETURN command. This means that to call
another subroutine (2) from one subroutine (1) as shown below, the RETURN
command is necessary for each subroutine.
Main program
GOSUB
Stack
Return address
RETURN
Subroutine 1
GOSUB
RETURN
Section 4-1
Program
Task 1
Task 2
Task 3
Operation
processing
Subroutine 2
RETURN
59

Advertisement

Table of Contents
loading

Table of Contents