Calling C function from asm prog

Hi there,

I am still struggling to call a C function from an assembler program

Here is the command used:

jsr $pff.c   I tried also jsr _pff.c

The result is always the same:

Error (asp100): Characters exist in expression

Any clue ?

Thks in advance for your help

Jean-Pierre

Parents Reply Children
  • It's now working fine !

    I used the following:

    jsr _pff to call a simple C function and

    jsr $open when parameters have to be transmitted

    Many thanks NGE for your kind help !!

  • Following successfully calling C functions from asm, I am now facing a new issue:

    My data are defined as follows in asm project

    ;********************************************************
    ; RAM area allocation
    ;********************************************************

    .section data_SB8, data

    record_size: .blkl 1

    but I don't know how to include variable and structure defined in C language functions to my data section

    defined in asm

    Here is an example of a structure defined in H file

    /* Directory object structure */

    typedef struct {
    WORD index; /* Current read/write index number */
    BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
    CLUST sclust; /* Table start cluster (0:Static table) */
    CLUST clust; /* Current cluster */
    DWORD sect; /* Current sector */
    } DIR;

    and variable defined in C file like:

    BYTE i, c;

    Thks for your help

  • There is no good way to define a c structure in asm. You can manually define offsets in asm for the variables in the c structure. But when you change the structure you need to redefine your asm offsets.

    A better way to use c structures in asm is to make use of the asm function also known as inline assembly. With this you can imbed asm in a c function. A small example from the NC100 compiler manual (chapter B2):

    void func(void) 
    { 
        short idata; 
        short a[3]; 
        struct TAG{ 
            short i; 
            short k; 
        } s; 
        : 
        asm(" MOV.W R0, $$[FB]", idata); 
        : 
        asm(" MOV.W R0, $$[FB]", a[2]); 
        : 
        asm(" MOV.W R0, $$[FB]", s.i); 
        (Remainder omitted) 
        : 
        asm(" MOV.W $$[FB], $$[FB]", s.i, a[2]); 
    }

    And:

    short idata; 
    short a[3]; 
    struct TAG{ 
        short i; 
        short k; 
    } s; 
    void func(void) 
    { 
        : 
        asm(" MOV.W R0, $$", idata); 
        : 
        asm(" MOV.W R0, $$", a[2]); 
        : 
        asm(" MOV.W R0, $$", s.i); 
        (remainder omitted) 
        : 
    } 

  • Thks NGE for your quick answer but my purpose is to call C from asm and not the opposite.

    My main project is in assembly and I just wanted to access a driver for sd card written in C

    The question is how to define an @ in RAM for the C structure not to define it in asm

  • I would approach this by having the C-code do all structure references using function calls from the assembly side read / write individual structure data:

    struct {
        int Member1;
        int Member2;
        int Member3:
    } Struct;

    int Get1(void) { return Struct.Member1; }
    int Get2(void) { return Struct.Member2; }
    int Get3(void) { return Struct.Member3; }
    void Put1(int Arg) { Struct.Member1 = Arg: }
    void Put2(int Arg) { Struct.Member2 = Arg; }
    void Put3(int Arg) { Struct Member3 = Arg: }

  • I do not understand: where are the function calls from the assembly side read / write individual structure data in your example ?

  • From assembly when you need to access the structure from the C-code, call the "Get" for a read and "Put" for a write.