English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 05 June 2021, 17:41   #1
deimos
It's coming back!
 
deimos's Avatar
 
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"
        );
    }
The interface to FFPFPA is:

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                            *
Trouble is, it's not working. Some values seem to work ok, others just return an empty string.

Can anyone check the wrapper code above?
deimos is offline  
Old 05 June 2021, 20:09   #2
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
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.
Samurai_Crow is offline  
Old 06 June 2021, 14:26   #3
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
Quote:
Originally Posted by Samurai_Crow View Post
Have you tried extern "C" {} in your header? C++ has hidden members like a "this" pointer in them.
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.
deimos is offline  
Old 06 June 2021, 15:44   #4
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
Found it. Fixed it.
deimos is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:12.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.06624 seconds with 13 queries