Specifications

SIMATIC Instructions
9-145
S7-200 Programmable Controller System Manual
C79000-G7076-C233-01
Subroutine, Return from Subroutine
The Call Subroutine instruction transfers control to the
subroutine (n). You can use a Call Subroutine instruction
with or without parameters. To add a subroutine, select
Edit > Insert > Subroutine from the menu.
The Conditional Return from Subroutine instruction is
used to terminate a subroutine based upon the preceding
logic.
Operands: n: Constant
Data Types: BYTE
Once the subroutine completes its execution, control
returns to the instruction that follows the Call Subroutine.
Figure 9-55 shows an example of the Call Subroutine,
and Return from Subroutine instructions.
Error conditions that set ENO for Call Subroutine with
parameters = 0:
SM4.3 (run-time), 0008 (maximum subroutine nesting
exceeded)
Note
Micro/WIN 32 automatically adds a return from each subroutine.
You can nest subroutines (place a subroutine call within a subroutine), to a depth
of eight. Recursion (a subroutine that calls itself) is not prohibited, but you should
use caution when using recursion with subroutines.
When a subroutine is called, the entire logic stack is saved, the top of stack is set
to one, all other stack locations are set to zero, and control is transferred to the
called subroutine. When this subroutine is completed, the stack is restored with the
values saved at the point of call, and control is returned to the calling routine.
Accumulators are common to subroutines and the calling routine. No save or
restore operation is performed on accumulators due to subroutine use.
L
A
D
S
T
L
SBR n
CRET
L
A
D
F
B
D
EN
SBRn
222 224
333
221
RET
RET
SBR