Section 9

Subroutines

When the same set of instructions needs to be used at more than one point in a program, memory space can be conserved by storing those instructions as a single subroutine.

The Mechanics

Go To Subroutine and Return

The G (go to subroutine) instruction is executed in the same way as the t branch, with one major difference: it establishes a pending return condition. Glabel, like tlabel,* transfers program execution to the line with the corresponding label (A to E, 0 to 9 or .0 to .9). However, execution then continues until the first subsequent n instruction is encountered – at which point execution transfers back to the instruction immediately following the last G instruction, and continues on from there.

Subroutine Execution

´bA

G.1

n

END

Execution transfers to line 000 and halts.

´b.1

n

RETURN

Execution transfers back to original routine after G.1

*A G or t instruction followed by a letter label is an abbreviated key sequence (no ´ necessary). Abbreviated key sequences are explained on page 78.

101

Page 101
Image 101
HP 15c Scientific manual Subroutines, Go To Subroutine and Return, Subroutine Execution, ´b.1, 101