A little bit of ASM-to-C (et vice-versa) with this compilation of documents I've done, maybe it helps.
http://www.valpocl.com/SuperVDP/superh_ ... etion.html
PS : pity I couldn't insert HTML :(
SuperH Registers Calling Convention
Moderator: BigEvilCorporation
Here's a minor thing I've seen missing on all SuperH calling convention docs I've seen. How functions that return a struct work, in something like this:
Main will pass the address of foo to InitThingy in register R1. The value of val will be passed in R4 like normal.
I checked this in a disassembly of GCC output when generating SH4 code. I don't know if different compilers handle this differently; I haven't seen this documented in anything official.
The GCC code I disassembled built newthing on the stack, then called memcpy to copy it over to foo, but it seems like it would be more efficient just to write to foo directly...
I can't remember if InitThingy would set R0 to anything special when it returns.
Code: Select all
struct thingy { int a,b,c; };
struct thingy InitThingy(int val)
{
struct thingy newthing = { val, 0, val*2 };
return newthing;
}
int main()
{
struct thingy foo = InitThingy(10);
// ...
}
I checked this in a disassembly of GCC output when generating SH4 code. I don't know if different compilers handle this differently; I haven't seen this documented in anything official.
The GCC code I disassembled built newthing on the stack, then called memcpy to copy it over to foo, but it seems like it would be more efficient just to write to foo directly...
I can't remember if InitThingy would set R0 to anything special when it returns.
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
Yeah, it's not part of the C spec, so everyone does something different. It's my main complaint about libdragon (SDK for N64 homebrew) - he uses struct passing for a number of functions, particularly the controllers.ElBarto wrote:Rule #1 in C when using struct : Never pass a struct to a function
Rule #2 in C when using struct : Never return a struct to from function