GOSUB     CALL
 
Syntax


GOSUB label

GOSUB ( expression )

[GOSUB] function/sub

    or

CALL label

[CALL]  function/sub

CALL ( expression )

Description


GOSUB is supported for backward compatibility, now FUNCTIONs and SUBs  would be the preferred method.  The GOSUB keyword is not required for calling a SUB or FUNCTION.

Execution jumps to a subroutine marked by line label. Always use RETURN to exit a GOSUB, execution will continue on next statement after GOSUB.

label may be defined as any valid identifier followed by a colon, and can be defined before or after the GOSUB. Do not include the colon in the GOSUB.

GOSUB or CALL preceeding a FUNCTION or SUB is optional, and is allowed for backward compatibility with other BASICs.  When GOSUB/CALL a FUNCTION the return value is discarded.

GOSUB or CALL (expression) will compute the expression and then call the resulting address,  Nost of our parts are running ARM Thumb code, so the least significant bit of that expression should be 1.

Forward declarations-

BASIC does not have a mechanism for defining SUB or FUNCTION ahead of their actual definition.  But for callback from an interrupt, a mechanism for calling a SUB has been added.  The SUB can not accept any parameters, and can not be a FUNCTION returning a value.

Example

'   original BASIC syntax

MAIN:
GOSUB message
END

message:
PRINT "Welcome!
return
'   example of callback

CALL_1_ADDR = 0                  '  globally define a CALLBACK address 

SUB CALLBACK_1
  #ifndef ARM_CODE_32BITS   ' only needed for backward compatability with LPC21xx
    CALL_1_ADDR OR= 1         ' indicate Thumb code  
  #endif
    GOSUB (CALL_1_ADDR)    ' do the callback
ENDSUB

'...


SUB sample 
    CALLBACK_1         ' do the callback
ENDSUB

'...

SUB SUB11
               ' eventually define SUB11
    PRINT 1234
ENDSUB

'...

CALL_1_ADDR = ADDRESSOF (SUB11)

Differences from other BASICs

See also