Nesting subroutine files, Using jsr – Rockwell Automation 1761-HHP-B30 MicroLogix 1000 with Hand-Held Programmer (HHP) User Manual

Page 220

Advertising
background image

Chapter 12
Using Program Flow Control Instructions

12–4

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).

Entering the Instruction

You enter the instruction from within the program monitor functional area.
Asterisks appear on the display to indicate that the HHP is waiting for data
entry (i.e., a number).

P 0 1 0

J S R

S B R #

1 0

2

L

3

U

ENT

1

FUN

To enter the function code, press:

Advertising