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 structure elements in assembly.

HI,

I am writing an assembly for a simple C function, I want to access structure elements whose values are set in C. I want to access the structure elements by using dot operator in assembly. For Eg.

Structure declaration In C file

is

typedef struct Mystruct
{
 int a;
 int b;
}Mystruct;

Mystruct Ostruct;

It is initialized as

 Ostruct.a = 10;
 Ostruct.b = 20;

Now the call goes to a function in assembly. I want to access the structure variables, I tried like

.global _Ostruct

MVKL _Ostruct,A3

MVKH _Ostruct,A3

LDW  *A3(Ostruct.a),A7

But Its giving assembly error like missing struct\union tag.

Can somebody help in getting me out of this issue. Should I redeclare the structure in assembly file to access ithe members or add a tag to the existing structure & use it?

 

Regards,

Santhosh

 

 

  • Santhosh,

    As you have seen, the dot operator is not recognized in assembly.

    You have a couple of choices.

    The best choice is to not do this in assembly, but implement your intended operation in C and use intrinsics if you need to access certain assembly instructions that are not commonly implemented by the C compiler. This will allow you to specify memory addresses and variables using C syntax. You can read about this in the C Compiler User's Guide, and probably in various articles on the TI Wiki Pages and elsewhere in answers in this forum.

    Your other choice is to look at the assembly output from the compiler by enabling the Build option to save the assembly output files. It may be -k, but check the Build Properties GUI to find out. Then find how the struct is defined within the assembly output and how it is accessed in the assembly output. They you can do it the same way in your assembly program.

    Regards,
    RandyP

     

    If this does not answer your question, please tell us more. If it does, please click the  Verify Answer  button, below.