SusiKette wrote:
According to few sites JSR subtracts 1 from the program counter before pushing it to the stack (should now point to the lower byte of the subroutine's address). Why?
This is wrong, it pushes the PC of the JSR instruction + 2; or in other words the 3rd byte of the JSR instruction; or in other words the PC of the next instruction - 1. It does not substract anything - rather than that it justs push the PC as it is when fetching the 3rd byte of the JSR instruction.
Practical example: Let's say we are at adress $b000 and that the instruction is JSR $ABCD. The memory is as follows:
Code:
B000 : $20
B001 : $CD
B002 : $AD
B003 : .... (next instruction is here)
In this case, $B002 will be pushed on the stack.
Quote:
Additionally one site says that RTS subtracts 1 from the value taken from the stack (pointing the JSR instruction) and one says it adds 1 (pointing the upper byte of the subroutine's address). Which one of these is correct?
The second site is correct, the first is wrong (*). RTS pull an adress from the stack, add one and continues execution from there.
Taking back our exaple, the adress $B002 will be retrived from the stack and incremented, and the 6502 will fetch the next instruction at adress $B003.
(*) Either that or your understanding of what they said is wrong.