A subroutine is any portion of a program context beginning with a line mentioned in and defined in the same context, as a GOSUB statement and ending with a RETURN statement.
When a running program encounters a GOSUB statement, it saves the current line number and then transfers control to the specified line. Execution continues normally until a RETURN statement is executed, at which point the program jumps back and resumes execution at the line after the GOSUB statement. Execution of a RETURN statement without a GOSUB will give an error.
If the subroutine is called by ON ERROR GOSUB, it can also include ERROR RETURN statements. A RETURN re-executes the statement which caused the error, while ERROR RETURN skips it.
Porting Issues
Under HTBasic, GOSUB and ALLOCATE use the same stack. Intermixing these statements can cause changes in available memory that are different from HP BASIC. In practice this causes no problems.