Commodore 64 (C64) Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Order in which a functions's arguments are set

 
Post new topic   Reply to topic    Commodore 64 (C64) Forum Index -> Scene
View previous topic :: View next topic  
Author Message
cjauvin
Newbie


Joined: 23 Jun 2012
Posts: 29
Location: Canada

PostPosted: Sat Jun 23, 2012 4:30 pm    Post subject: Order in which a functions's arguments are set Reply with quote

Hi,

I have a function fetching its boolean arguments in the A and X registers. For some reason, the order in which I set the arguments, prior to the function call, seems to matter, because:

Code:

lda #0
ldx #1
jsr func


behaves differently than:

Code:

ldx #1
lda #0
jsr func


Admittedly my ML skills are rather limited, but I really don't see how this could make a difference. Am I missing something?
Back to top
View user's profile Send private message Visit poster's website
groepaz
Immortal Grandmaster of C64
Immortal Grandmaster of C64


Joined: 13 Oct 2004
Posts: 4697

PostPosted: Sat Jun 23, 2012 4:32 pm    Post subject: Reply with quote

i can assure you that it makes no difference whatsoever =)
_________________
Back to top
View user's profile Send private message
cjauvin
Newbie


Joined: 23 Jun 2012
Posts: 29
Location: Canada

PostPosted: Sat Jun 23, 2012 7:57 pm    Post subject: Reply with quote

I found the answer.. of course I was doing something silly: starting the function right away with a branching instruction, which of course relied on the loading order of the registers.

I guess I'd need some ML "best practices", to guard against such mistakes!
Back to top
View user's profile Send private message Visit poster's website
Thraka
Newbie


Joined: 01 Jan 2007
Age: 32
Posts: 35
Location: Washington State

PostPosted: Sat Jun 23, 2012 9:13 pm    Post subject: Reply with quote

LOL. I too have been starting up learning ASM, and I've been doing funny things like that too. It gets easier. A few nights ago it really started to click and I'm having an easier time reading it all now.
Back to top
View user's profile Send private message
THEWIZ
Forum Junkie
Forum Junkie


Joined: 17 Jun 2006
Posts: 527

PostPosted: Sun Jun 24, 2012 6:29 am    Post subject: Reply with quote

cjauvin wrote:
I found the answer.. of course I was doing something silly: starting the function right away with a branching instruction, which of course relied on the loading order of the registers.

I guess I'd need some ML "best practices", to guard against such mistakes!

Best practices: Unless you have inputs into the routine, dont rely on any values from outside the routine.

So you should never do:

routine: bne somewhere

It should be:
routine: bit a (or cpx #1 or...)
bne somewhere

For one thing the caller may not set the two input registers right away,
Of course, we dont always use "best practices" so you may want to define an input into your routine to be whether the carry or zero flag is set.
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Commodore 64 (C64) Forum Index -> Scene All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Tip: Get C64 Forever for super-comfy C64 emulation with pre-installed games, demos and other goodies!


Powered by phpBB © 2001, 2005 phpBB Group