First page Back Continue Last page Overview Graphics
Subroutine Call Overview
JSR SubroutineName calls a subroutine
RTS causes the program to return from the subroutine.
- Program execution returns to the statement after the call.
- RTS should be the last statement in the subroutine.
The stack pointer must be initialized (only once) before making a subroutine call, e.g. using
Subroutines will be discussed in more detail later, but are presented here so that you can use them in your programs. The following example code fragment shows a call to a subroutine that adds 2 to the value in accumulator A. The RTS statement in the subroutine returns to the STAA PORTS statement. The stack pointer needs to be loaded (only once) using an LDS #$c00 statement. The stack pointer must be loaded prior to the subroutine call.
Add2ToA: ADDA #2