This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

accessing C structure members in c28x assembly

Hello everyone,

how can i access a C declared structure in assembly?

ex.

// C declaration in "something.h"

...

struct MY_STRUCT {

       unsigned int      First;

       unsigned int      Second;

       unsigned int      Third;

};

extern struct MY_STRUCT MyStruct;

...

// declaration as global variable in C file, "globals.c"

...

struct MY_STRUCT MyStruct;

...

Then i need do refer to MyStruct.Third in assembly, and i don't know how .

How can i refer to that element in assembly language?

If i have in "program.asm" something like

      .ref   _MyStruct

....

      MOV AR1,#_MyStruct      ; this load AR1 with address of MyStruct, and works.

....

     MOV AR1,#_MyStruct.Third     ; this doesn't work and gives me error.

....

How can i access directly Third element. ?

  • Hi Emanuele,

    There are several posts that discuss the intermixing between C and assembly:

    Inline assembly:

    http://e2e.ti.com/support/development_tools/compiler/f/343/p/77852/278440.aspx

    Variable argument passing:

    http://e2e.ti.com/support/development_tools/compiler/f/343/p/65548/236650.aspx

    C++ interfacing:

    http://e2e.ti.com/support/development_tools/compiler/f/343/p/31416/109859.aspx

    Calling C functions from assembly code (C28x):

    http://e2e.ti.com/support/development_tools/compiler/f/343/p/73689/267932.aspx

    The C compiler user's guide contains a section called Register conventions that talks about register usage in the C environment.

    Regards,

    Gautam

  • Thanks for reply Gautam,

    I've checked yor link to previous post, and i can't find anything related to my question.

    I've read C ++ compiler optimizing manual, section 'interfacing C and assembly'. I have read C function calling convention, and how CPU perform 'context saving' and 'context restoring'. Actually i'm working in C code, and  writing an assembly interrupt routine to speed up the code (optimization is not enought). This works greatly!

    Now i'd like to know if there is a way to access C structure mebers from assembly.

    ex. in C

    MyVar = AdcResult.ADCRESULT1;

    in assembly i'd like to do something similiar without redefining address of every register i use.

    something like.

        MOV   AR0,#_AdcResult.ADCRESULT1

      MOV   @_MyVar,*AR0

    what i do now is defining position for ADCRESULT1 as

    _ADCRSLT1      .set         0b01h 

    ...

       MOV   AR0,#_ADCRSLT1      

       MOV   @_MyVar,*AR0

    I'just want to know if it is possible to use a point operator in assembly too. I don't know if it is allowed.

    In spru513u, Assembly Language Tools, on page 318 there is 13.2.13 Structures and Unions paragraph. There it is written, in last line before 13.2.14, This allows you to refer to _a_variable.a_member in your assembly code.


    That is exactly what i need, but i'cant let it work.

    Thanks

  • ex. in C

    MyVar = AdcResult.ADCRESULT1;

    in assembly i'd like to do something similiar without redefining address of every register i use.

    something like.

        MOV   AR0,#_AdcResult.ADCRESULT1

      MOV   @_MyVar,*AR0

    what i do now is defining position for ADCRESULT1 as

    _ADCRSLT1      .set         0b01h 

    ...

       MOV   AR0,#_ADCRSLT1      

       MOV   @_MyVar,*AR0

    I'just want to know if it is possible to use a point operator in assembly too. I don't know if it is allowed.

    I've never heard or seen any implementations that you're trying to do. But I'm pretty much sure that pointer's implementation is not possible in assembly as you're doing!

    This is how you can implement pointers in assembly: http://www.friedspace.com/assembly/pointers.php

    Regards,

    Gautam

  • Hello Gautam,

    Gautam Iyer said:
    This is how you can implement pointers in assembly: http://www.friedspace.com/assembly/pointers.php

    i've checked your link.

    That article is about INTEL assembly. I'm writing in c28x assembly, i think they are not the same. Maybe point operator is not allowed in intel assembly, but in c28x it is, or maybe it is not allowed in intel assembly and c28x assembly. Thanks however , and any other hints please?

  • Thanks however , and any other hints please?

    The above remarks was 'in general' and not specifically for intel architecture.

    For C28x assembly you can refer this doc:

    5850.TMS320C28x Assembly Language Tools.pdf

    Regards,

    Gautam

  • you should be able to. It would probably be something like this

    MOVW  DP, #_AdcResult                                    ; load adcresult page into DP

    MOV      AR0, @_AdcResult.ADCRESULT0         ; linker will resolve address from top of page

    My syntax might be off. In that case i recommend you write a short C snippet, then go into the properties of the file (file only) and set the following:

    C2000 compiler -> advanced options -> advanced debug options -> --symdebug:none

                                       "                                                         -> Assembler options -> --keep_asm & --c_src_interlist

    Build the file, in the debug folder you should find its assembly.

  • ok, found it,

    first delare a structure in c, for example in "header.h"

    struct MY_STRUCT {

    int M1;

    long M2;

    float M3;

    } MyStruct;

    then in asm file, at the beginning can type:

    .cdecls    C,NOLIST

    %{

    #include "header.h"

    %}

    ;..... and then in asm code

    ;..... can acces C declared strictures as

    MOVL   @_MyStruct.M2,ACC

    ;.......

    .cdecls directive let me include C header in asm files and generate suuitable asm code.

    Emanuele Peruzzi