Quote:
Originally Posted by Hedeon
For optimal compatibility I also need to save those registers and I want it to do without asm. I looked through the vbcc manual but cannot find anything on this. Is this possible?
|
Possible, yes - but very ugly.
The only way I can think of (without modifying vbcc) would be to use an inline assembly function to save the registers. It would look something like this:
Code:
int d1wrapper() = "\tmovem.l a0-a1/d1,-(a7)\n\tjsr _func_inner\n\tmovem.l (a7)+,a0-a1/d1\n";
int func(int param1,int param2)
{
return(d1wrapper());
}
int func_inner(int dummy1, int dummy2, int dummy3, int dummy4, int param1, int param2)
{
return(param1+param2);
}
(The extra dummy parameters are to account for the extra entries on the stack - one extra return address and three registers.)
Edit: if you don't need to return a value to the caller, you can simply declare your function with the __interrupt attribute. Unfortunately, because it saves and restores not just d1/a0/a1, but d0 as well, you lose the ability to return a value!
Edit 2: If your function uses register parameters, rather than stack based parameters, (and I guess it does if it's a library function) then the hideous hack with dummy parameters shouldn't be necessary - you should be able to just omit those.)