Chapter 5 Instruction Words
5 - 4
5.2 Program Control Instructions
This section explains the details of program control instructions.
entry and end statements Instructions to start and end the main program
- Format
Format Description
entry
This instruction indicates the beginning of the main program.
(This instruction must be described at the top of the main program.)
end This instruction indicates the end of the main program.
- Explanation
The entry and end statements indicate the beginning and end of the main program, respectively. Each
program always requires these instructions.
- Sample program
entry : The main program begins.
:
FW = 1 : Start forward rotation of the motor.
wait 10.00 : Wait 10 seconds.
stop : Stop inverter output.
wait 10.00 : Wait 10 seconds.
:
end : The main program ends.
sub and end sub statements Instructions to start and end a subroutine
- Format
Format Description
sub <subroutine name> This instruction indicates the beginning of a subroutine.
end sub
This instruction indicates the end of a subroutine.
Control is returned to the calling routine.
- Explanation
The sub and end sub statements indicate the beginning and end of a subroutine, respectively.
<subroutine name>: Specifies the name of a called subroutine. This subroutine name is the first
argument (branch destination) of the call instruction in the calling routine.
Note: Subroutines can be nested in up to eight layers. A subroutine programmed with a structured
instruction (i.e., sub, for, while, until, select, or ifs) is counted as one nesting layer. Therefore, when
a for-next loop statement is described in a subroutine, there are two nesting layers.
- Sample program
sub sub1 : Subroutine "sub1" begins.
:
FW = 1 : Start forward rotation of the motor.
wait 10.00 : Wait 10 seconds.
stop : Stop inverter output.
wait 10.00 : Wait 10 seconds.
:
end sub : Subroutine "sub1" ends.