Here is the explanation how this works when you use JSL -> RTS:
*Means that when the PC (program counter) "returns" (weather RTS or RTL), it pulls the stack + 1. I've learned it from Ersanio's ASM tutorial (not the SMW version).
Give thanks to RPG hacker for working on Asar.
Code
PHK ;\This will push the 24-bit address location PEA.w .jslrtsreturn-1 ;/after the JML (below) into the stack* PEA $yyyy-1 ;>This modifies the RTS in the pointed routine (below) to jump to an RTL in same bank.* ;^This RTL then pulls the stack (which is the 24-bit address) to jump to a location after the JML JML $xxxxxx ;>The desired routine that ends with RTS .jslrtsreturn
*Means that when the PC (program counter) "returns" (weather RTS or RTL), it pulls the stack + 1. I've learned it from Ersanio's ASM tutorial (not the SMW version).
Originally posted by Ersanio
About JSR and JSL, and RTS and RTL:
Imagine that there is a JSR opcode located at $8000, and there is an LDA at $8003, and RTS at $B000. A JSR instruction is 3 bytes long (JSR $xxxx). So we have this:
Now, what JSR does is, pushing the next instruction’s location - $0001 onto the stack. This means, that the value $8002 is pushed on the stack. Then JSR jumps to the specified address. What RTS does, is pulling that $8002 from the stack and adding $0001 to it, and storing it into the program counter register, causing the program to jump back to the instruction after that JSR.
JSL and RTL work the same way, except these push and pull 24-bit addresses. JSL pushes the long address - 1 onto the stack and jumps to the specified address, and RTL pulls the long address +1 onto the stack and jump to it.
Imagine that there is a JSR opcode located at $8000, and there is an LDA at $8003, and RTS at $B000. A JSR instruction is 3 bytes long (JSR $xxxx). So we have this:
Code
$8000 JSR $B000 $8003 LDA #$01 … $B000 RTS
Now, what JSR does is, pushing the next instruction’s location - $0001 onto the stack. This means, that the value $8002 is pushed on the stack. Then JSR jumps to the specified address. What RTS does, is pulling that $8002 from the stack and adding $0001 to it, and storing it into the program counter register, causing the program to jump back to the instruction after that JSR.
JSL and RTL work the same way, except these push and pull 24-bit addresses. JSL pushes the long address - 1 onto the stack and jumps to the specified address, and RTL pulls the long address +1 onto the stack and jump to it.
Give thanks to RPG hacker for working on Asar.