05 June 2021, 17:41 | #1 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
Calling assembly from C++, values returned on stack
I'm trying to relearn C++ after more than 20 years of being smart enough to not touch it.
I'm trying to write a wrapper around Motorola's 68343 floating point code, just to see if I can make it transparently supported as if it was part of the language, and maybe, possibly, improving on what's in mathffp.library and amiga.lib. What I have works, mostly, but I'm getting weirdness when I convert to ascii. This is with the bartman vscode environment, so I don't have amiga.lib and the fpa function in it, but I do have the FFPFPA function from Motorola, so I'm doing this: Code:
inline void fpa(char * const buffer, const FFP value) { __asm volatile ( " movel %[value], %%d7 \n" " \n" " jsr FFPFPA \n" " \n" " moveal %%sp, %%a0 \n" " moveal %[buffer], %%a1 \n" " moveq #13, %%d7 \n" "1: moveb (%%a0)+, (%%a1)+ \n" " dbra %%d7, 1b \n" " moveb #0, (%%a1) \n" " lea (14, %%sp), %%sp \n" : // outputs : // inputs [value] "g" (value), [buffer] "g" (buffer) : // clobbers "d7", "a0", "a1", "cc" ); } Code:
* FFPFPA * * FLOAT TO ASCII * * * * INPUT: D7 - FLOATING POINT NUMBER * * * * OUTPUT: D7 - THE BASE TEN EXPONENT IN BINARY * * FOR THE RETURNED FORMAT * * SP - DECREMENTED BY 14 AND * * POINTING TO THE CONVERTED * * NUMBER IN ASCII FORMAT * * * * ALL OTHER REGISTERS UNAFFECTED * * * * CONDITION CODES: * * N - SET IF THE RESULT IS NEGATIVE * * Z - SET IF THE RESULT IS ZERO * * V - CLEARED * * C - CLEARED * * X - UNDEFINED * Can anyone check the wrapper code above? |
05 June 2021, 20:09 | #2 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
|
Have you tried extern "C" {} in your header? C++ has hidden members like a "this" pointer in them.
|
06 June 2021, 14:26 | #3 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
That doesn't seem to help, and the bit where the problem appears doesn't deal with any objects. Also, I've now discovered that my code just blows up if I remove one of my debugging print statements, so maybe I've just written a bunch of junk that can never work.
|
06 June 2021, 15:44 | #4 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
Found it. Fixed it.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Years away always returned! | DrFruit | Member Introductions | 2 | 15 October 2019 19:52 |
Calling OS Functions? | nocash | Coders. System | 5 | 03 February 2016 09:27 |
The A2000 returned from the sea | jman | support.Hardware | 25 | 27 August 2011 18:28 |
Calling it a day... | killergorilla | project.Killergorilla's WHD packs | 57 | 28 March 2011 06:48 |
Calling All Contributors! | fiath | project.SPS (was CAPS) | 9 | 28 October 2010 12:22 |
|
|