Re: [Flashforth-devel] Fwd: Re: C function with more parameters in W0-W7
Brought to you by:
oh2aun
From: Mikael N. <mik...@fl...> - 2015-06-08 20:18:13
|
And to answer my own question. It can be done like below __attribute__((address(0x1000))) float Ctest(unsigned short a, unsigned short b, unsigned long int c, float x, float y) { a = a + 100; b = b / a; c = c * b; x = sqrtf( (float)c - x ); y = y / x; return y; // 4.5894021E-1 } On 08.06.2015 23:03, Mikael Nordman wrote: > How did you solve it ? > > In my tests you get this problem because the Ctest.c file is linked after > the FF binary code into a the area where FF thinks is free space for the > dictionary. Compiling some FF code will then overwrite the C code. > > This happens if you also include the float package into the compilation. > If you do not include the float package, Ctest code will fit into memory > before the FF binary code and all is fine. > > How can the linker be forced to link the C-code before the FF code ? > Bu defining some new sections for the linker perhaps. > > There is no reason to save W0..W7 before calling the C function because > these registers are not 'live' in FF between words. > > Mikael > > On 06.06.2015 19:30, om1zz wrote: >> Solved, see examples. >> I. >> >> _____________________________________________________________ >>>> Od: "om1zz" <om...@vo...> >>>> Komu: Mikael Nordman <mik...@fl...> >>>> Datum: 04.06.2015 19:00 >>>> Předmět: C function with more parameters in W0-W7 >>>> >>>> MIke, I cope with following issue: >>>> >>>> I have a Cfunction, with 5 parameters, returning float. >>>> >>>> So I am using W0-W7 for params. >>>> >>>> The strange: >>>> First time after the fresh flash the Cfun (when pasting the below >>>> into teraterm) returns good result: >>>> >>>> decimal 100 2000 5. $0fdb $4049 $0fdb $4049 Ctest hex ok<#,ram> fa36 >>>> 3eea >>>> >>>> I can do it repeatedly, I always get good results. >>>> >>>> decimal 100 2000 5. $0fdb $4049 $0fdb $4049 Ctest hex ok<#,ram> fa36 >>>> 3eea >>>> decimal 100 2000 5. $0fdb $4049 $0fdb $4049 Ctest hex ok<#,ram> fa36 >>>> 3eea fa36 3eea >>>> decimal 100 2000 5. $0fdb $4049 $0fdb $4049 Ctest hex ok<#,ram> fa36 >>>> 3eea fa36 3eea fa36 3eea >>>> >>>> In the moment as I do something via prompt (before or after playing >>>> with Cfun), the Cfun returns garbage (and also it corrupts the system). >>>> >>>> For example, I cannot get good results when after the fresh flash I do: >>>> $0fdb $4049 2constant pi >>>> decimal 100 2000 5. pi pi Ctest hex >>>> >>>> I've tried push/pop W4-W7, but the same. >>>> I. >>>> >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> >>> _______________________________________________ >>> Flashforth-devel mailing list >>> Fla...@li... >>> https://lists.sourceforge.net/lists/listinfo/flashforth-devel >>> |