JSR
JSR (short for "Jump to SubRoutine") is the mnemonic for a machine language instruction which calls a subroutine; for those familiar with BASIC programming, this is the machine language "equivalent" to GOSUB. It does this by first incrementing the program counter by two, pushing the result onto the stack, high-byte first (for retrieval when the subroutine is done and needs to hand back control to the calling part of the program), and then transfers program execution to the specified address, similar to JMP.
When the subroutine ends in an RTS, this instruction pulls the address from the stack, further increasing it to a total of 3 bytes from the address of the initial JSR instruction, reaching the address of the instruction immediately after the JSR.
Addressing mode[edit | edit source]
Opcode | Addressing mode |
Assembler format |
Length in bytes |
Number of cycles | |
Dec | Hex | ||||
32 | 20 | Absolute | JSR nnnn | 3 | 6 |
JSR only supports the absolute addressing mode, as shown in the table at right. In the assembler format listed, nnnn is a two-byte (16-bit) address.
CPU flags[edit | edit source]
JSR does not affect any of the CPU's status flags.