Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > using of rts
2013-11-09 21:46
MrXaliasH
Account closed

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
2013-11-09 21:52
Sixx

Registered: May 2005
Posts: 231
Yeah, i use rts all the time.
2013-11-09 22:35
Zyron

Registered: Jan 2002
Posts: 2381
RTS is only for JSR. BNE etc aren't jumps, so nothing you return from.
2013-11-09 22:37
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?
2013-11-10 09:00
MrXaliasH
Account closed

Registered: Oct 2013
Posts: 11
@lft, Zyron:

Thanx, that was exactly what i wanted to know! Now it is clear for me.
2013-11-11 07:53
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.
2013-11-11 09:39
Oswald

Registered: Apr 2002
Posts: 5127
rtfm
2013-11-11 09:46
JackAsser

Registered: Jun 2002
Posts: 2038
Quote: rtfm

A bit harsh, but yeah... Posting TFM for reference: http://www.obelisk.demon.co.uk/6502/reference.html#RTS
2013-11-11 15:08
MrXaliasH
Account closed

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
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Impetigo/Crescent
CA$H/TRiAD
CentralperK/Patagonia
Beast/Crescent
megasoftargentina
TheRyk/MYD!
Alakran_64
WVL/Xenon
iAN CooG/HVSC
Guests online: 295
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Codeboys & Endians  (9.7)
4 Mojo  (9.6)
5 Coma Light 13  (9.6)
6 Edge of Disgrace  (9.6)
7 Signal Carnival  (9.6)
8 Wonderland XIV  (9.5)
9 Uncensored  (9.5)
10 Comaland 100%  (9.5)
Top onefile Demos
1 Nine  (9.7)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.5)
6 Scan and Spin  (9.5)
7 Onscreen 5k  (9.5)
8 Grey  (9.5)
9 Dawnfall V1.1  (9.5)
10 Rainbow Connection  (9.5)
Top Groups
1 Artline Designs  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Performers  (9.3)
5 Censor Design  (9.3)
Top Graphicians
1 Mirage  (9.7)
2 Archmage  (9.7)
3 Sulevi  (9.6)
4 Pal  (9.6)
5 Hein  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2025
Page generated in: 0.083 sec.