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
  • That makes sense - some assemblers require symbol references, some don't, and some have options to ignore undefined symbols.  One could also potentially get the C-compiler to generate such a reference by doing something like this:

    extern int pff; int GetPFF(void) { return pff; }

  • Thanks NGE, you were right !

    I did have a '.glb' declaration but I forgot the underscore character (shame on me...)

    Now the compilation process is completed without any error (see below)

    assembler processing now

    C:\0DATA\32C\32C Projects\R32C_GFORCE_GRAPHIC\R32C_GFORCE_3\main.a30
    R32C/100 Series Assembler system V.1.02.01
    Copyright (C) 2006 (2007 - 2010) Renesas Electronics Corporation.
    and Renesas Solutions Corporation. All rights reserved.
    macro processing now
    assembler processing now
    ----*----*----*----*----*----*----*----*----*----*----
    TOTAL ERROR(S) 00000
    TOTAL WARNING(S) 00000
    TOTAL LINE(S) 05416 LINES
    CODE 00000629(000275H) program
    ( C:\0DATA\32C\32C Projects\R32C_GFORCE_GRAPHIC\R32C_GFORCE_3\main.a30 )
    ----*----*--
    Phase R32C/100 Assembler finished

    But now linkage pass 2 is faulty, see result below:

    Phase R32C/100 Linker starting

    Linkage Editor (ln100) for R32C/100 Series V.1.02.00.001

    Copyright (C) 2006 (2007 - 2010) Renesas Electronics Corporation.

    and Renesas Solutions Corporation. All rights reserved.

    SentinelRMS (C) 1989-2006 SafeNet, Inc. All rights reserved.

    now processing pass 2

    Projects\R32C_GFORCE_GRAPHIC\R32C_GFORCE_3\Debug\main.r30"

    C:\0DATA\32C\32C Projects\R32C_GFORCE_GRAPHIC\R32C_GFORCE_3\main.a30(461) : '_pff' value is undefined

    Any clue ?

  • I dived in an old project with a R32C/111 where in the C file I have the following:

    void initSystem(void);
    
    void initSystem(void){
    
    }

    The declaration of the function can also done in an include. Maybe this declaration is needed for the linker.

    And in the assembly:

    .glb		_initSystem
    jsr.a		_initSystem

  • 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.

Reply Children
No Data