[C] Passing parameters by registers
Moderator: Stef
[C] Passing parameters by registers
Hello,
my question is not really SGDK related, but I've read some sources of SGDK and saw some functions implemented in asm.
But it seems that the parameters of the functions are sent using the stack.
Is it possible to make the compiler send parameters using registers, as it's more often done when programming in asm ?
my question is not really SGDK related, but I've read some sources of SGDK and saw some functions implemented in asm.
But it seems that the parameters of the functions are sent using the stack.
Is it possible to make the compiler send parameters using registers, as it's more often done when programming in asm ?
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: [C] Passing parameters by registers
Actually the GCC version provided in SGDK does not allow it even by forcing maximum optimization level or using the fastcall keyword.tryphon wrote:Hello,
my question is not really SGDK related, but I've read some sources of SGDK and saw some functions implemented in asm.
But it seems that the parameters of the functions are sent using the stack.
Is it possible to make the compiler send parameters using registers, as it's more often done when programming in asm ?
I tried to force it by using some asm pragma but it was not really easy to implement your function then.
The problem with fastcall is that is not a standardized calling convention method and maybe for 68000 it doesn't even exist (which explain why it doesn't make any difference). Honestly except for function you use more than one hundred of time *per frame* it is not a big issue of passing parameters through the stack. When you have many parameters (more than 4/5 parameters) it may be better to pass a pointer to a structure owing all the parameters though.
-
- Very interested
- Posts: 149
- Joined: Sat Nov 17, 2012 3:58 am
-
- Very interested
- Posts: 149
- Joined: Sat Nov 17, 2012 3:58 am
Hey StefStef wrote:Of course you can do it by using assembly code, it's just that you cannot force C code to use registers when calling functions.Count SymphoniC wrote:Wait. So it couldn't be done by including pre assembled .asm code? Would I have trouble mixing asm and C using SGDK?
Interesting... well it's not something I've tried yet, but plan on doing so very soon. So if I was linking asm with my C code and I was calling an asm subroutine from within C, would I want to make sure that I wiped my data and address registers before returning to the C portion or does it really even matter? Btw, did you ever solve the .xgm pausing instruments issue?
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
When you call asm subroutine from C, you have to make sure the subroutine you call fetch parameters from stack.Count SymphoniC wrote: Hey Stef
Interesting... well it's not something I've tried yet, but plan on doing so very soon. So if I was linking asm with my C code and I was calling an asm subroutine from within C, would I want to make sure that I wiped my data and address registers before returning to the C portion or does it really even matter?
What you can do is to have sort of 2 methods enter point depending you call it from C or asm :
Code: Select all
myMethodC:
move.l (sp)+, d0-d1/a0-a1
myMethodASM:
...
I don't specifically remember this issue, do you have a music example producing it ? I made some fixes on the XGM driver (and still i am) so hopefully i got this one fixed =)Btw, did you ever solve the .xgm pausing instruments issue?
-
- Very interested
- Posts: 149
- Joined: Sat Nov 17, 2012 3:58 am