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

How to make use of xdata space when combining C lang and Assembly

Hello Sir,

This is Vijay Manohar.

I am trying to add C code to the already existing code.

Assembly code also making use of XDATA space. As I was getting memory overflow problems, I have been defining all the variables in xdata space itself in C code. My question is there any possibilty that C language uses memory consumed by assembly. If that is the case, how to aviod it. We have about 8k of xdata space. Is there any declaration that tells the compiler to use a particular area in xdata for C code.

Help is highly appreciated.

Regards,
Vijay Manohar

  • Is there any declaration that tells the compiler to use a particular area in xdata for C code.

    The compiler has very little influence on where variables/segments are placed - because in most cases, this is the job of the linker.

    If you want to make sure that there are no conflicts, you will need to refer to the linkers documentation, and its output files.

  • As I was getting memory overflow problems, I have been defining all the variables in xdata space itself in C code.

    Also, you might want to review this approach. Accessing variables in xdata carries significant performance and code size penalties when compared to data/idata.

    xdata is best used to hold data structures (arrays/structs) that are accessed infrequently.

    Usage of data memory can be reduced by using memory overlaying and moving infrequently-used data to xdata.

  • As Christoph says, it is the Linker's job to assign all the various memory requirements of its various input modules to the available memory spaces.

    The Linker doesn'r really care whether its input object modules come from 'C', assembler, or any other language, or a mixture of languages.

    Therefore, if you're getting overflow errors, you're just using too much memory!

    Overlaying will help - make sure that both 'C' and assembler are creating overlayable data...

  • Thanks for the reply.

    Is there any directive to the linker asking it to use the
    particular memory space in the xdata space.

    Regards,
    Vijay Manohar

  • "Is there any directive to the linker asking it to use the particular memory space in the xdata space."

    Yes, but how will that help?

    If the Linker can't fit all your data into the available space when given free rein, how is it going to manage if you interfere by restricting its choices?!