Search code examples
c++assemblyembeddedmicrochip

Accessing functions in an ASM file from a C++ program?


Over here I asked about translating an ASM file to C, and from the responses it looked like there was no reasonable way to do it. Fine. So one of the responses suggested I just make use of the functions as-is and be done with it. Sounds good.

But how?

Holy crap I've tried everything I can think of! I'm using a Microchip brand MCU (PIC18F4480) and a Microchip brand IDE (MPLAB IDE) and the ASM files are Microchip authored... so you'd think I'd find some way of making use of them! So far no luck at all.

I don't know anything about ASM (Assembly). I code in C++ and frankly that's not going to change. There has got to be a way to access the functions in the Microchip ASM files without rewriting all my code in a new language.

If anyone wants to take a look, the ASM files and application notes are here.


Solution

  • Looking at PIDInt.asm, it should be fairly straight-forward to call the functions from C/C++. First, you declare extern variables for everything listed in VARIABLE DEFINITIONS:

    extern unsigned char error0, error1; /* etc */
    

    Then, you declare extern functions for all the things that have a "Function:" comment, taking no arguments and returning no result:

    extern void Proportional(); // extern "C" for C++
    

    To call one of them, you fill the input variables, call the function, and read the output variables.