04.03.2013 Views

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

GOSUB<br />

<strong>Syntax</strong><br />

gosub label{[argument1,...,argumentN]}{,DataResult}<br />

• Label - the go to label of the subroutine to be executed.<br />

Commands<br />

• Argument - is user defi ned arguments to send to the called subroutine. The only limit to the<br />

amount of arguments used is program memory.<br />

• DataResult - is an optional variable to store the value returned from called subroutine.<br />

Supported<br />

• BA - Supported<br />

• BAN - Supported<br />

• BAP - Supported<br />

• BAP40 - Supported<br />

Description<br />

The GOSUB command will jump to a specifi ed label. After executing the code at the jump label a<br />

RETURN command is then used to return the program to the next command after the last called<br />

GOSUB.<br />

If you are familiar with some BASIC languages there is typically a limit to what is called nesting. This<br />

is where multiple GOSUB...RETURN statements are nested inside of each other. There is no limit to<br />

this with <strong>Basic</strong> <strong>Micro</strong> <strong>Studio</strong> other than the size of the available stack memory.<br />

GOSUB stores the address of the next command on the stack and jumps to the specifi ed label. User<br />

specifi ed arguments can be defi ned in the subroutine. A return value from the subroutine can be<br />

stored in the variable that is specifi ed by the GOSUB DataResult argument.<br />

Notes<br />

1. Subroutines should exit via the RETURN command, which clears the saved address from the<br />

stack and returns to the command following the GOSUB. Do not use BRANCH or GOTO when<br />

exiting a subroutine.<br />

2. User defi ned arguments must match the number of arguments defi ned at the subroutine. If they<br />

do not match, a stack overfl ow or underfl ow will happen.<br />

3. If a subroutine returns a value, the GOSUB is not required to use it.<br />

112

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!