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.

How to define stucture in asm?

Hi,

How to use structure in asm? I have tried the example, see below snippet, in Page 76 of spru186v.pdf. TMS320C6000 Assembly Language Tools v 7.3 User's Guide. It cannot get through at all. Anyone can give me a compilable example with this small example?

Thanks.

 

....................

COORDT .struct                                  ; structure tag definition

X              .byte ;

Y              .byte

T_LEN     .endstruct

COORD   .tag COORDT                       ; declare COORD (coordinate)

                .bss COORD, T_LEN            ; actual memory allocation

                 LDB *+B14(COORD.Y), A2 ; move member Y of structure

                                                              ; COORD into register A2

 

  • Robert W said:
    It cannot get through at all.

    I'm not sure what you mean.  Please precisely describe what you expect to get, and what you actually get.

    Thanks and regards,

    -George 

  • Your example works fine for me and the latest TI C6000 compiler tools.  The input file I used is attached.  Compare it against your file?

    5050.test.asm

    %> cat test.asm
    COORDT .struct            ; structure tag definition
    X              .byte      ;
    Y              .byte
    T_LEN     .endstruct
    COORD   .tag COORDT       ; declare COORD (coordinate)
            .bss COORD, T_LEN ; actual memory allocation

            LDB *+B14(COORD.Y), A2 ; move member Y of structure
                                   ;;  COORD into register A2

    %> cl6x -al test.asm

    %> cat test.lst
    TMS320C6x Assembler Unix v7.4.1 Tue Sep  4 16:55:27 2012

    Tools Copyright (c) 1996-2012 Texas Instruments Incorporated
    test.asm                                                             PAGE    1

           1                    COORDT .struct            ; structure tag definition
           2          00000000  X              .byte      ;
           3          00000001  Y              .byte
           4          00000002  T_LEN     .endstruct
           5                    COORD   .tag COORDT       ; declare COORD (coordinate)
           6 00000000                   .bss COORD, T_LEN ; actual memory allocation
           7
           8 00000000 0100012C-         LDB *+B14(COORD.Y), A2 ; move member Y of structure
           9                                                   ;;  COORD into register A2

    No Assembly Errors, No Assembly Warnings

    %> dis6x test.obj
    Disassembly of test.obj:

    TEXT Section .text (Little Endian), 0x20 bytes at 0x0
    00000000             .text:
    00000000   0100012c           LDB.D2T1      *+B14[1],A2
    00000004   00000000           NOP
    00000008   00000000           NOP
    0000000c   00000000           NOP
    00000010   00000000           NOP
    00000014   00000000           NOP
    00000018   00000000           NOP
    0000001c   00000000           NOP

  • Hi,

    With CCS v5 IDE, your test.asm building process cannot build because there is no main. My previous question is that I cannot find any way to build a project with that stucture definition.

    I have found a thread on the forum.

    http://e2e.ti.com/support/development_tools/compiler/f/343/t/192527.aspx

    It says the red part is not supported by the compiler. That is the cause I cannot build the stucture. I still don't know whether you can build a structure with the red part (The compiler calculates the offset).

    Thanks.

     

    MY_STRUCT_type .struct

    fee            .word

    fi             .word

    foe            .word

    fum            .word

    MY_STRUCT_LEN  .endstruct

    MY_STRUCT      .tag MY_STRUCT_type

    ;              .bss MY_STRUCT, MY_STRUCT_LEN

                   .bss MY_STRUCT, 16

     

  • More clearly, can you use .tag directive for a stucture?

  • It says the red part is not supported by the compiler. That is the cause I cannot build the stucture. I still don't know whether you can build a structure with the red part (The compiler calculates the offset)

    With CGT 7.3.3 it works. Mybe you could post the erros reported by the assmbler.

    You can also try the $sizeof() operator:

    COORDT .struct
    X .byte
    Y .byte
      .endstruct

    COORD    .tag COORDT
        .bss COORD, $sizeof(COORDT)

    Note that if the struct is shared between C and asm, you should consider using the .cdecls directive and define the struct in a C header file (then looking at the asm listing you can view how the C structure are converted).

  • Hi,

    Try the attached project

    If incompatible with your CCS (it is generated with CCS 5.1, CGT 7.3.3), you can extract the source file hello.c, coord.h, coord.asm and insert them in a new project.

    Inside coord.asm you can choose to use the C struct declaration or the assmbler one (just change  "use_c_declaration    .set 0" to "use_c_declaration    .set 1" to use the C header file).

    4846.c66_asm_struct_example.zip