beautypg.com

11ć11, 2 nested subroutines – Rockwell Automation 1772-LP3 PLC - 2/30 Programmable Controller Programming and Operations Manual User Manual

Page 212

background image

Jump Instructions and

Subroutine Programming

Chapter 11

11Ć11

Figure 11.9

Representative Subroutine Area

(ą)

(ą)

|ą|

|ą|

| / |

|ą|

| / |

LBL

XX

( RET )

(ą)

|ą|

LBL

XX

( RET )

(ą)

|ą|

LBL

XX

( RET )

Main Program

Subroutine Area

(Subroutine #1)

(Subroutine #2)

(Subroutine #8)

End

The label is the first

instruction in each

subroutine.

Up to sixtyĆfour (64)

subroutines can

be programmed

if no jumps are

programmed.

The return is the

last instruction in its

subroutine.

Subroutine boundary serves

as end statement for main

program.

A subroutine may call another subroutine (Figure 11.10a) which, in turn,
may call another subroutine. This nesting process can continue until eight
levels of calls are involved.

Figure 11.10 (a) shows three levels of nested subroutines. The main
program calls Level 1 at label 01 (a). Level 1, in turn, calls Level 2 at label
02 (b). Note that Level 1 subroutine issued the command to jump to label
02 before all the steps in Level 1 were completed. Likewise, Level-2
subroutine issued the command to jump to label 03 (c) before completing
all Level-2 steps.

Level-3 subroutine, the last subroutine in the next, is executed to its return
instruction (d). Each return instruction returns processor execution to the
instruction immediately following the JSR that initiated the subroutine (e
and f). Execution continues from that point.

11.3.2
Nested Subroutines