SecondBASIC Documentation v3

Home / Command Reference / Declare


Description: Sets the declaration of a user defined routine.


Declare <RoutineType> (<ParameterList>) [As <Type>]

Part Description
<RoutineType> Required. This tells the compiler what type of routine you've created. Acceptable values are:
  • Sub
  • Function
  • Asm Sub
  • Asm Function
<ParameterList> Optional. Parameter Lists are optional and their restrictions depend on whether the routine is an ASM routine or not.

For non-ASM routines, you would declare your arguments just like you would in the Dim and Global commands. See the example below.

For ASM routines, see below in the notes section.

<Type> Optional. The As <Type> is used only on functions, not Asm Functions or either type of Sub. If the As <Type> is omitted, the compiler will look to see if the function name has an identifier and will assign the <Type> automatically.

Notes (Taken from the Basiegaxorz documentation):

The parameter list specifies which values from the called function go into the CPU registers. The parameter list can accept the data registers, d0-d7, which will return the actual values of what the programmer passes to the sub or function.

When specifying a data register, the size of the data register (byte, word, or long) has to be specified somewhere in the parameter list, along with the actual data register. For instance, to put a byte value into d0, you could use either the d0.b or d0 as byte (both will do the same thing). The same goes for word, and long data types. If an address register, a0-a7, is specified, the pointer that holds the value that is passed to the sub or function will be returned. The pointer will only return the value in the heap. It will not return the actual location of a variable.

A size doesn't have to be specified for address registers, since a long, or 32-bit magnitude is always assumed. However, a data type has to be specified for an address register, so that the compiler will be able to distinguish whether it should return a pointer for an integer value, or a long value, or a string (all which have different offsets in the heap).

Acceptable parameters:


        MySub 10, 10
        Print MyFunc(12,12)
        Print MyASMFunc(5,1)
        ' Example Sub
Declare Sub MySub(x As Integer, y As Integer)
        Print x * y
End Sub
        ' Example Function
Declare Function MyFunc(x As Integer, y As Integer) As Integer
        Return x * y
End Function
        ' ASM Example Function
Declare Asm Function MyASMFunc(d0.l, d1 As Byte)
        add.l d1, d0
End Function