Menu

Mixing Ada+C+Assembly

2011-04-26
2012-09-15
  • Alexandre Bencz

    Alexandre Bencz - 2011-04-26

    Hi :)

    I'm trying to add codes in C and Assembly with ada, but I have some doubts,
    such as:

    working with C functions that require more than one argument, eg:

     int sum(int a, int b, int c, int d)
    {
    return a+b+c+d;
    }
    

    and how can I join with assembly code in Ada.

    Thanks

     
  • pcas1986

    pcas1986 - 2011-04-27

    The answer to your first question is to pass across a pointer to a record of
    the four integers you wish to add together in C. You should read the
    "Interfaces to other languages" annex in the Ada Ref Manual. It was Annex B
    for Ada 95. Don't know about 2005 or 2010. You will almost certainly find some
    C interface examples in the standard GNAT libraries.

    I've never done an assembly language interface so I cannot help you there. I
    vaguely remember seeing an example in one of John Barnes' earlier books on Ada
    - an Ada 83 version I think.

    You could also ask your questions on the usenet comp.lang.ada. Its a lot more
    active than this service and they get many questions similar to yours.

     
  • Simon Wright

    Simon Wright - 2011-04-27

    I just spent 15 minutes answering your question, but %^$£$@%$ Sourceforge lost
    it (I really need to remember that Sourceforge doesn't work well with Safari
    and tabs).

    See the GNAT User Guide for interfacing with
    C
    and inline
    assembler
    (at the end).

    And, Paul isn't correct about needing to wrap the arguments in a record (the C
    expects 4 arguments, not one!) See the ARM.

     
  • Martin Krischik

    Martin Krischik - 2011-04-27

    Hi bencz.

    A very exotic place for this question ;-) . May I humbly suggest comp.lang.ada
    for questions of this type:

    http://groups.google.com/group/comp.lang.ada/topics

    While the two answers you got are certainly good at comp.lang.ada you might
    get even more interesting answers to you questions.

    Martin

     

Log in to post a comment.