Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Digital Archaeology » Computer Arcana » Commodore » Commodore 8-bit » register usage when mixing assembler and C with cc65?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
register usage when mixing assembler and C with cc65? [message #260907] Tue, 15 July 2014 19:59 Go to next message
Anonymous
Karma:
Originally posted by: Frank Buss

When I use assembler functions from my C code with cc65, what are the
rules for the registers? I couldn't find it in the documentation.

- does the C environment expect the assembler code to save the A/X/Y
register values?

Is there a difference between fastcall and normal defined functions with
and without parameters?

- only one char parameter for A in a fastcall function, do I need to
save X and Y?

- a fastcall function without parameters and void return, do I need to
save the registers?

- a normal assembler function, void return, do I need to save the registers?

What about the flags, e.g. do I need to save the carry flag in my
assembler function?

--
Frank Buss, http://www.frank-buss.de
C64 MIDI interface, preorder: http://www.frank-buss.de/c64/midi/buy.html
Re: register usage when mixing assembler and C with cc65? [message #261097 is a reply to message #260907] Wed, 16 July 2014 16:18 Go to previous messageGo to next message
Aaron Daughtry is currently offline  Aaron Daughtry
Messages: 226
Registered: July 2013
Karma: 0
Senior Member
On 2014-07-15 23:59:18 +0000, Frank Buss said:

> When I use assembler functions from my C code with cc65, what are the
> rules for the registers? I couldn't find it in the documentation.
>
> - does the C environment expect the assembler code to save the A/X/Y
> register values?
>
> Is there a difference between fastcall and normal defined functions with
> and without parameters?
>
> - only one char parameter for A in a fastcall function, do I need to
> save X and Y?
>
> - a fastcall function without parameters and void return, do I need to
> save the registers?
>
> - a normal assembler function, void return, do I need to save the registers?
>
> What about the flags, e.g. do I need to save the carry flag in my
> assembler function?

I think you get the best answers on the cc65 mailing list(s)

--
SD!
Re: register usage when mixing assembler and C with cc65? [message #261100 is a reply to message #261097] Wed, 16 July 2014 22:29 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: Frank Buss

SD! wrote:
>
> I think you get the best answers on the cc65 mailing list(s)

Good idea, I just sent it to the mailing list referenced on cc65.org

--
Frank Buss, http://www.frank-buss.de
C64 MIDI interface, preorder: http://www.frank-buss.de/c64/midi/buy.html
Re: register usage when mixing assembler and C with cc65? [message #262512 is a reply to message #260907] Sun, 27 July 2014 14:33 Go to previous message
Harry Potter is currently offline  Harry Potter
Messages: 1304
Registered: March 2012
Karma: 0
Senior Member
On Tuesday, July 15, 2014 7:59:18 PM UTC-4, Frank Buss wrote:
> When I use assembler functions from my C code with cc65, what are the
> rules for the registers? I couldn't find it in the documentation.
>
I admit that I'm not totally knowledgeable about the matter, but I think cc65 would save the regbank whenever it calls another function from one that uses registers. I also think that, other than the sp and A/X, it doesn't need most things to be saved. Also, if a function doesn't return anything, I think cc65 ignores A/X. Anyway, I've been mostly successful in writing assembler with cc65 C code.

> Is there a difference between fastcall and normal defined functions with
> and without parameters?
>
The only difference of which I know is that, in fastcall, the last parameter is kept in A/X.

> - only one char parameter for A in a fastcall function, do I need to
> save X and Y?
>
Y doesn't matter, but I keep seeing assembler functions in system libraries set X to 0 when returning a char.

> - a fastcall function without parameters and void return, do I need to
> save the registers?
>
You shouldn't, but I don't see a difference in this case between default declaration and fastcall declaration. BTW, can anybody tell me the difference between fastcall and __fastcall__? The docs were a little confusing. :(
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Dirmenu updated!
Next Topic: Re: Tenex Computer Express
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Apr 20 01:10:37 EDT 2024

Total time taken to generate the page: 0.01711 seconds