View Single Post
Old 07 April 2020, 01:14   #10
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 890
Originally Posted by Hedeon View Post
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:

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)

int func_inner(int dummy1, int dummy2, int dummy3, int dummy4, int param1, int 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.)

Last edited by robinsonb5; 07 April 2020 at 10:07.
robinsonb5 is offline  
Page generated in 0.06560 seconds with 11 queries