register usage when mixing assembler and C with cc65? [message #260907] |
Tue, 15 July 2014 19:59 |
|
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 |
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 #262512 is a reply to message #260907] |
Sun, 27 July 2014 14:33 |
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. :(
|
|
|