User Manual

MCP Series
Brushed DC Motor Controllers
MCP Series User Manual
178
RETURN
Syntax
return {DataResult}
DataResult - an optional value to return to the gosub statement, that can be an expression,
constant or variable.
Description
GOSUB stores the address of the next command on the stack and jumps to the specied label.
After executing the code at the jump label a RETURN command is used to remove, from the
stack, the address stored by GOSUB and then jumps to that address.
Notes
Subroutines must exit via the RETURN command, which clears the saved address from the
stack and returns to the command following the GOSUB. User dened arguments must match
the number of arguments dened at the subroutine. If they do not match, a stack overow or
underow will happen. If a subroutine returns a value, the GOSUB is not required to use it or
specify a return value variable.
Example
The result will be 110. The GOSUB command has two arguments and includes a DataResult
variable. The values 10 and 100 are passed to the subroutine MyAdd. The values are then loaded
into the variables arg1 and arg2. RETURN can have an expression, so the variables arg1 and
arg2 are added and returned to the variable result.
Result var long
Main
Gosub myadd[10,100],result
puts 0,[“Result =”,dec result]
End
Arg1 var long
Arg2 var long
MyAdd [arg1,arg2]
Return arg1+arg2
See Also:
GOSUB