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

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: 229
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

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: 5094
rtfm
2013-11-11 09:46
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
2013-11-11 15:08
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
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
csabanw
Alakran_64
Broti/DT/KRN
Yogibear/Protovision
Quetzal/Chrome
Exile/Anubis
Guests online: 90
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Graphicians
1 Mirage  (9.8)
2 Archmage  (9.7)
3 Pal  (9.6)
4 Carrion  (9.6)
5 Sulevi  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.052 sec.