Return from subroutine.
The return command is used with a matching gosub command, to return program flow back to the main program at the end of the sub procedure. If a return command is used without a matching gosub beforehand, the program flow will crash.
Return is also used to complete an interrupt routine to return program flow back to the main program where it was interrupted. If a return command is not executed, a 'goto main' or similar is used instead, then interrupts cannot be re-enabled and the program will likely not behave as expected.
Call a gosub subroutine
Flash an LED multiple times using a gosub subroutine
- Code Example:
main: let b2 = 15 ; set b2 value gosub flsh ; call sub-procedure let b2 = 5 ; set b2 value gosub flsh ; call sub-procedure end ; stop accidentally falling into sub flsh: for b0 = 1 to b2 ; define loop for b2 times high B.1 ; switch on output 1 pause 500 ; wait 0.5 seconds low B.1 ; switch off output 1 pause 500 ; wait 0.5 seconds next b0 ; end of loop return ; return from sub-procedureCopy Code Submit an Example
Return from an interrupt
This program demonstrates an interrupt event when input C.1 goes high. A LED on output B.1 will flash quickly when the interrupt is entered and slowly when it is not.
- Code Example:
setint %00000010, %00000010, C ; Interrupt when pin C.1 goes high main: toggle B.1 ; Slowly flash LED on B.1 pause 1000 goto main interrupt: for b1 = 1 to 10 ; Quickly flash LED on B.1 toggle B.1 pause 100 next setint %00000010, %00000010, C ; Re-enable interrupt return ; Continue back in main programCopy Code Submit an Example
Submit Your Own Code!
You must be logged in to submit code examples. Login now.