11 - 80 11 - 80
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
GOSUB RETURN
Instruction
GO to SUBroutine/RETURN
• Branches to a subroutine and returns to the specified line number.
GOSUB <line number 1>
RETURN [ <line number 2> ]
Syntax
line number 1
• • • •
Specify the starting line number of the subroutine to
be branched.
line number 2
• • • •
Specify the line number to return.
Examples
GOSUB 100
• • • •
Branches to the subroutine of line number 100.
Description
• The GOSUB to RETURN instruction branches to the subroutine by GOSUB, then returns
to the instruction after the GOSUB instruction, specified line number, or label by the
RETURN instruction.
• <line number> can also be specified by a label.
• The same subroutine can be called many times in a program.
• Subroutines can be nested as long as the memory capacity allows.
An “Out of Memory” error occurs when the memory runs out.
10
500
GOSUB1000
1000
1500RETURN
GOSUB2000
2000
2500RETURN
• The RETURN instruction returns the control to the following instruction of the GOSUB
instruction that branched to the subroutine.
• While multiple RETURN instructions can be specified within one subroutine, they have to
correspond to GOSUB instructions correctly.
• A subroutine must be used by a GOSUB instruction. If it is executed by itself, a “RETURN
without GOSUB” error occurs when the RETURN instruction is executed.
Содержание A1SD51S
Страница 183: ...11 13 11 13 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS RUN Before swap A 0 H924 A 1 H1159 After swap A 0 H1159 A 1 H924 OK...
Страница 331: ...11 161 11 161 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the CON ON OFF STOP and ZOPEN functions and Section 7 4...
Страница 557: ...11 387 11 387 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the CHR SPACE and SPC functions...
Страница 629: ...11 459 11 459 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the ZOPEN ZSEND and ZCNTL instructions and Section 7 3 4...
Страница 645: ...11 475 11 475 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the ZEVENT ZSIGNAL and DEF ZEVENT instructions...