Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

register usage when mixing assembler and C with cc65?

97 views
Skip to first unread message

Frank Buss

unread,
Jul 15, 2014, 7:59:18 PM7/15/14
to
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

SD!

unread,
Jul 16, 2014, 4:18:34 PM7/16/14
to
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!

Frank Buss

unread,
Jul 16, 2014, 10:29:05 PM7/16/14
to
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

Harry Potter

unread,
Jul 27, 2014, 2:33:15 PM7/27/14
to
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. :(
0 new messages