Programming

Appendix A

Subroutines

What Are Subroutines?

A subroutine is a program written between the SBN(092) and RET(093) instructions in a special subroutine area. A subroutine is called from the main program using the SBS(091), MCRO(099), or JSB(982) instruction.

Subroutines can be used in the following three ways with the FQM1.

Type of subroutine

Description

Calling instruction

 

 

 

Normal subroutines

Normal subroutines are executed without passing parameters.

SBS(091)

 

 

 

Subroutines for

• Parameters can be passed to the subroutine.

MCRO(099)

which parameters

• The results of processing in the subroutine can be returned to the

 

are passed

main program.

 

 

 

 

 

• Flags can be used to access the input condition to the subroutine

JSB(982)

 

while the subroutine is being executed.

 

 

• It’s possible to check to see if a subroutine has been executed in the

 

 

past.

 

 

• Parameters can be passed to and from the subroutine using storage

 

 

registers.

 

 

 

 

Using Normal Subroutines

A normal subroutine is written between the SBN(092) and RET(093) instructions and called using the SBS(091) instruction.

1.Write the program to be executed between SBN(092) and RET(093).

2.Set the subroutine number for the operand of SBN(092).

3.Call the subroutine using SBS(091)

Main program (section 1)

Subroutine (section 2)

Subroutine (section 3)

SBS

100

SBN

100

Processing

RET

SBN

10

Processing

Set the subroutine number to call. Here, the subroutine number is 100.

Set the the subroutine number. Here, the subroutine number is 100.

Set the the subroutine number. Here, the subroutine number is 10.

RET

264

Page 287
Image 287
Omron FQM1-MMP21 What Are Subroutines?, Using Normal Subroutines, Type of subroutine Description Calling instruction