456 Rockwell Automation Publication 1756-RM003N-EN-P - October 2011
Chapter 11 Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Use these guidelines to program a jump to a subroutine.
The following diagram illustrates how the instructions operate.
Do not use a JSR instruction to call (execute) the main routine.
· You can put a JSR instruction in the main routine or any
other routine.
· If you use a JSR instruction to call the main routine and
then put a RET instruction in the main routine, a major fault
occurs (type 4, code 31).
Calling Routine
JSR
SBR
RET
RET
JSR
1.If you want to copy data to a tag in the
subroutine, enter an input parameter.
2.If you wan t to co py a re sult of the
subroutine to a tag in t his routine, enter a
return parameter.
3.Enter as man y in put an d return
parameters as you need.
SBR
1.If th e J SR in struction ha s an input
parameter, enter an SBR instruction.
2.Place the SBR instruct ion as the first
instruction in the routine.
3.For each in put p arameter in th e JSR
instruction, enter the tag into which you
want to copy the data.
42974
Subroutine
RET
1.If the JSR instruction has a return parameter, enter an
RET instruction.
2.Place th e RET ins truction as th e la st instruction in t he
routine.
3.For each return parameter in the JSR instruction, enter a
return parameter to send to the JSR instruction.
4.In a ladder routine, place ad ditional RET instructions to
exit the subroutine based on different input conditions, if
required. (Fu nction block rou tines only pe rmit one RET
instruction.)