Programming, Nesting subroutine files, Using jsr – Rockwell Automation 1761 MicroLogix 1000 Programmable Controllers User Manual
Page 183

Using Program Flow Control Instructions
10–5
Nesting Subroutine Files
Nesting subroutines allows you to direct program flow from the main program to a
subroutine and then on to another subroutine.
You can nest up to eight levels of subroutines. If you are using an STI subroutine,
HSC 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.
JSR
6
JSR
7
SBR
RET
SBR
SBR
JSR
8
RET
RET
Example of Nesting Subroutines to Level 3
Program
Main
Subroutine File 6
Level 1
Subroutine File 7
Level 2
Subroutine File 8
Level 3
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.
You must program each subroutine in its own program file by assigning a unique
file number (4–15).
Programming