377
Subroutine Instructions
Section 5-27
5-27 Subroutine Instructions
Subroutines break large control tasks into smaller ones and enable you to
reuse a given set of instructions. When the main program calls a subroutine,
control is transferred to the subroutine and the subroutine instructions are
executed. The instructions within a subroutine are written in the same way as
main program code. When all the subroutine instructions have been executed,
control returns to the main program to the point just after the point from which
the subroutine was entered (unless otherwise specified in the subroutine).
5-27-1 SUBROUTINE ENTER – SBS(91)
Description
A subroutine can be executed by placing SBS(91) in the main program at the
point where the subroutine is desired. The subroutine number used in
SBS(91) indicates the desired subroutine. When SBS(91) is executed (i.e.,
when the execution condition for it is ON), the instructions between the
SBN(92) with the same subroutine number and the first RET(93) after it are
executed before execution returns to the instruction following the SBS(91) that
made the call.
SBS(91) may be used as many times as desired in the program, i.e., the same
subroutine may be called from different places in the program).
N
:
Subroutine number
000 to 255
Definer Data Areas
SBS(91) N
Ladder Symbol
SBS(91) 00
SBN(92) 00
RET(93)
END(01)
Main program
Subroutine
Main program