Installation manual
Publication 1747-RM001G-EN-P - November 2008
6-4 Program Flow Instructions
Nesting Subroutine Files
Nesting subroutines allows you to direct program flow from the main program
to a subroutine and then on to another subroutine. The following rules apply
when nesting subroutines.
• With Fixed and SLC 5/01 processors, you can nest subroutines up to
four levels
• With SLC 5/02 and higher processors, you can nest subroutines up to
eight levels. If you are using an STI subroutine, DII subroutine, I/O
event-driven interrupt subroutine, or user fault routine, you can nest
subroutines up to three levels from each subroutine.
The following figure illustrates how subroutines may be nested.
An error occurs if more than the allowable levels of subroutines are called
(subroutine stack overflow) or if more returns are executed than there are call
levels (subroutine stack underflow).
Using JSR
When the JSR instruction is executed, the controller jumps to the subroutine
instruction (SBR) at the beginning of the target subroutine file and resumes
execution at that point. You cannot jump into any part of a subroutine except
the first instruction in that file.
JSR
6
JSR
7
SBR
RET
SBR SBR
JSR
8
RET RET
Main
Program
Level 1
Subroutine File 6
Level 2
Subroutine File 7
Level 3
Subroutine File 8