| |
MrXaliasH
Registered: Oct 2013 Posts: 11 |
using of rts
Hi guys,
short and simple question:
Can rts be used for all kind of jumps (bne, beq, bcc aso...) or just for jsr (as this stores the current adress on stack) ? I didn't find a clear information about that.
Thanx for your help
Holger |
|
| |
Sixx
Registered: May 2005 Posts: 229 |
Yeah, i use rts all the time. |
| |
Zyron
Registered: Jan 2002 Posts: 2381 |
RTS is only for JSR. BNE etc aren't jumps, so nothing you return from. |
| |
lft
Registered: Jul 2007 Posts: 369 |
I might have misunderstood the question, but here goes: BNE etc. do not push a return address. RTS jumps to whatever is on the stack. Thus, RTS won't return to the location following the BNE.
That said, RTS can be used for all kinds of stunts, like computing a destination address, pushing it to the stack, and then jumping by executing RTS.
Does that clear things up? |
| |
MrXaliasH
Registered: Oct 2013 Posts: 11 |
@lft, Zyron:
Thanx, that was exactly what i wanted to know! Now it is clear for me. |
| |
satpro Account closed
Registered: Oct 2013 Posts: 7 |
You can put any address value you want on the stack but anything pulled from the stack with RTS will first be incremented before jumping to it so you would want to make the address you push one less than the intended target.
JSR pushes the address of the last byte of its operand on the stack, not the address of the instruction that immediately follows it.
lda #>target-1
pha
lda #<target-1
pha
rts
will take you to target. Push the high byte of target-1 first because the cpu loads the program counter with the low byte first, then the high byte. |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
rtfm |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Quote: rtfm
A bit harsh, but yeah... Posting TFM for reference: http://www.obelisk.demon.co.uk/6502/reference.html#RTS |
| |
MrXaliasH
Registered: Oct 2013 Posts: 11 |
@JackAsser thx for the link
@Oswald NOW I WILL READ THERE... and don't ask such (for you simple) questions ;) still learning and trying to understand the magic in this little beauty called 6502 :P |