This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using C structs in assembly files

I'd like to declare a struct in a C51 file and access members of the struct in an assembly (A51) file. Is there an easy way to do this?

I can declare the name of the struct as "extrn" in the assembly file, but how do I get the offsets of the struct members into the assembly file?

-dean

  • Assembler knows nothing about structures - or any other 'C' data type bigger than a byte.

    You will just have to do it all manually.

    That's the whole point of high-level languages - they relieve you of the tedium of doing all this manually.

    As a starting point, you could just write a piece of 'C' that accesses every member of the structure, then use the SRC directive to have the compiler convert that to assembler for you...

  • Thanks for the reply
    That's kind of what I thought. I was hoping to get some legacy assembly code to work with some new C code in a way that would allow the compiler to guarantee address compatibility between the assembly code and the C code.

    The members of the struct are located in xdata space in fixed locations in a dual port RAM so the risk of them moving in the future is quite low. Therefore, I'll just set them manually using

    symbol_name xdata <address>

    If there's anyone that knows a neat way to get offset information for members of a C struct passed into an assembly file (presumably by the linker) I'd be eager to hear about it.
    -dean