Basic30 Language Reference
Sub ... End Sub Statements |
Define a sub procedure.
[ { Public | Private |
External }] [ RegParams ] Sub name (
[parameters]) [ interruptFlag ]
[statements]
[Exit Sub]
End Sub |
- name
- Required name for this sub procedure.
- parameters
- Optional list of parameters to be passed to this procedure.
- interruptFlag
- Optional flag instruction the compiler on what type of interrupt this
procedure will be.
- [statements]
- Optional block of statements that make up the body of the procedure.
- Public
- Optional keyword to define this procedure as a public member when
compiling to a library file. If omitted, private access is used.
- Private
- Optional keyword to define this procedure as a private member when
compiling to a library file. If omitted, private access is used.
- External
- Optional keyword to mark this procedure as being defined in an external
file which will be linked to the project after compiling. If omitted,
private access is used.
- RegParams
- Optional keyword to cause the compiler to pass parameters to this
procedure using registers W0 - W7 instead of using the stack.
Parameters are loaded into registers from left to right starting with W0.
A 32 bit value will use two registers, with the first register being an even
number. If this
option is used, an underscore character will be appended to the sub name to
make it compatible with procedures and libraries generated by other
compilers. Parameters being passed to a procedure that uses register
parameters must be simple values (IE: a variable or literal) and not an
equation ( IE: a+15 )
Notes:
- By default, Basic30 statements are not case sensitive and the procedure
name is converted to all upper case. In order to allow access to
standard link libraries such as the ones available from the Microchip
website, Basic30 will preserve the case of a procedure definition when it is
defined as External RegParams. You can however call the
procedure later with any mixture of upper or lower case.
- When a procedure is defined as External RegParms [statements] and
End Sub must be left off the definition
Related Statements:
- Exit Sub
- Exit this sub procedure, returning control back to the calling
procedure.
- Continue For
- Skip any remaining statements and continue with the next iterations of
the loop.
Examples
Sub main()
init()
TurnOnLED(3)
End Sub
Sub init()
' initialization code goes here
End Sub
Sub TurnOnLED(led as uByte)
' Code to turn on the requested LED
End Sub
' Define a procedure in an external library
Extern RegParams Sub OpenTimer1(config as uInteger, period as uInteger)
' The case of the procedure name MUST match the case of the
procedure in the link library
' because the linker is case sensitive
'
' Also, End Sub or End Function MUST not appear in an
External RegParams definition
Also See:
Function ... End Function