JXX-Commands: "Jump If ..."

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > JXX. - Jump - Instructions >

JXX-Commands: "Jump If ..."

JSR. - Jump SubRoutine (Label)

Previous Top Next


MiniRobotLanguage (MRL)

 

JSR./ GSB. Unconditional Subroutine-Jump

Jump SubRoutine / GoSub

 

 

Intention

 

This is a Subroutine call (GOSUB - like). JSR./GSB. invoke a subroutine at the given Label, keep the Return-line on the Return Stack. It will returns to the statement following the JSR./GSB. after reaching a RET. - Command.

 

What is a subroutine?

A subroutine is a Sub-program in your Main-program. Mostly subroutines encapsule an specific part of the overall job of your script.

 

Note that it has two names: GSB. and JSR..

These two are completely equal.

 

Usage is easy:

 

GSB.Label

' This is where we continue after the return

ENR.

 

:Label

' Do something here

RET.

 

Can i use Subroutine parameters?

Yes, the variables §§_01 ... §§_25 are hold the Subroutine Parameters.

The number of given parameters is available in $$_00.

 

If you specify just Variables as Parameter, the Content is only copied,

and the Type of the Variable is preserved.

 

' Example

VAN.$$NUM=5.09

GSB.AddMe|$$NUM|§§NUX

ENR.

:AddMe

VAO.$$PAA=§§_01

GVT.$$PAA|$$RES

MBX.We preserved the Variabletype: $$RES (=5, numeric)

RET.

 

Can i just jump out of a Subroutine?

 

If you plan to end the script anyway, then yes.

If you plan to invoke other subroutines later, then better not.

In this case use the:

 

    JRR. - Jump and Reset Return-Stack

    RRS. - Reset Return Stack

 

commands to clean up the Return-stack before/while jumping out.

 

 

Speed in Ticks:

This command uses typically between 30 to 60 Ticks.

 

You can also call Subroutines in the same way like with JSR./GSB. with the following commands:

 

    STW. - Description with the "W", or "V"-Option

    ! SCW - Search-Child-Window with the "W", or "V"-Option

    ITW. with the "W", or "V"-Option

    ICW. with the "W", or "V"-Option

    JIV. - Jump-If-Variable or

    any other of the JIX. - Jumps, when using the ":"-Label Option

 

 

 

 

Syntax

 

JSR.P1[|P2..|Px]

 

 

Parameter Explanation

 

P1 - TXT (Label) or Variable containing the Label.

P2 ... Px -(optional) Parameters for subroutine

 

 

 

 

Example

 

'***********************************************

' Example 1 - without Parameters,

'***********************************************

 

DBM.2

JSR.Laba

CAL.$$AAA=3+(9*$$AAA)+2.5

PRT. Resultat ist: $$AAA

END.

 

:Laba

: $$AAA=10

RET.

 

'***********************************************

' Example 2 - with Parameter

'***********************************************

 

DBM.2

: $$LAA=Laba

JSR.$$LAA|10

CAL.$$AAA=3+(9*$$AAA)+2.5

PRT. Resultat ist: $$AAA

END.

 

:Laba

: $$AAA=§§_01

PRT. $$AAA

RET.

 

 

'***********************************************

' Example 3 - with Parameter, uses Macros, GSB.
' and also returns Result.

'***********************************************

' Name; First Name; Street; ZIP-Code; ID-Number

'

$$PAT=?exeloc\Test.txt

$$DEL=,

$$FNA=James,Mary,John,Patricia,Robert,Jennifer,Michael,William,Elizabeth,David,Barbara

$$FNA=$$FNA,Richard,Susan,Joseph,Jessica,Thomas,Sarah,Charles,Karen,Christopher,Nancy

 

$$LNA=JOHNSON,WILLIAMS,JONES,BROWN,DAVIS,MILLER,WILSON,MOORE,TAYLOR

$$LNA=$$LNA,ANDERSON,THOMAS,JACKSON,WHITE,HARRIS,MARTIN,THOMPSON

$$LNA=$$LNA,GARCIA,MARTINEZ

VAR.$$TIM=#time#

$$FIN=

FOR.$$LOP|1|255

  GSB.Get_Lastname

  GSB.Get_Firstname

  POP.$$TX1

  POP.$$TX2

  GSB.Get_Streetname

  POP.$$TX3

  GSB.Get_ZipCode

  POP.$$TX4

  $$IDN=$$LOP

  FMT.$$IDN|0000

  $$LIN=$$TX1$$DEL$$TX2$$DEL$$TX3$$DEL$$TX4$$DEL$$IDN

  $$FIN=$$LIN$crlf$$$FIN

NEX.

DBP.$$FIN

CTF.$$PAT|$$FIN

CAL.$$TIM=#time#-$$TIM|i

MBX. Operation took: $$TIM seconds.

ENR.

'===========================================================

:Get_Firstname

VAO.$$RES

%Get_Random_Element $$FNA|$$RES

PUV.$$RES

RET.

'-----------------------------------------------------------

:Get_Lastname

VAO.$$RES

%Get_Random_Element $$LNA|$$RES

PUV.$$RES

RET.

'-----------------------------------------------------------

' P1 - List to use

' P2 - Variable for Result

: %Get_Random_Element 2

GSB.get_random_elem|§§§01|§§§02

END%

 

:get_random_elem

SAV.Save|$$OUT|$$LST|$$MIN|$$MAX|$$LAN

VAO.$$OUT=§§_02

VAR.$$LST=§§_01

%Get_Listcount $$LST

POP.$$MAX

$$MIN=1

RND.$$MIN|$$MAX|$$RES

SBD.$$LST|$$DEL|$$RES|$$LAN

VTM.$$LAN

VAI.$$OUT=$$LAN

SAV.Restore

RET.

'-----------------------------------------------------------

:Get_Streetname

SAV.Save|$$TXA|$$TXB|$$TXC

GSB.Get_Lastname

GSB.Get_Firstname

POP.$$TXA

POP.$$TXB

RND.1|99|$$NUM

$$TXC=$$TXA-$$TXB-Street. $$NUM

PUV.$$TXC

SAV.Restore

RET.

'-----------------------------------------------------------

:Get_ZipCode

SAV.Save|$$RES

RND.30000|92000|$$RES

PUV.$$RES

SAV.Restore

RET.

'-----------------------------------------------------------

: %Get_Listcount 1

GSB.Get_Listcount|§§§01

END%

 

:Get_Listcount

SAV.Save|$$CNT|$$PAR

$$PAR=§§_01

GSC.$$PAR|$$DEL|$$CNT|d

PUV.$$CNT

SAV.Restore

RET.

'-----------------------------------------------------------

 

 

 

 

 

Remarks

 

The variables §§_01 ... §§_25 are used for Parameters.

The number of given parameters is available in §§_00.

 

JSR. - unlike JNF. - does NOT open a local Variables/local Stack-Space for local variables.

 

Therefore Variables in a Subprogram called with JSR. are currently not explicitly local.

 

You can also call Subroutines in the same way like with JSR./GSB. with these commands:

 

    STW. - Description with the "W", or "V"-Option

    ! SCW - Search-Child-Window with the "W", or "V"-Option

    ITW. with the "W", or "V"-Option

    ICW. with the "W", or "V"-Option

    JIV. - Jump-If-Variable or

    any other of the JIX. - Jumps, when using the ":"-Label Option

    any of the FEX.-Enumeration Instructions

 

 

 

Limitations:

 

There is no depth limit for Subroutine calls. recursive calls are allowed.

 

 

 

See also:

 

    RET. - RETurn

    JIV. - Jump-If-Variable

    JIZ. - Jump-If-Zero

    JIN. - Jump if Not zero

    JOR. - Jump On Repeat-Count

    JME. - Jump on More or Equal

    JLE. - Jump on Less or Equal

    JMP. - Jump to Label

    JNF. - Jump New File

    RTS. - ReTurn from Subprogram