I have a MCS51 project which is compiled in small memory model, now I want to add a module to the project, the source files of the module comes from other non-C51 project, so I want to compile these source files with C51 in small memory model, but want to allocate all the global variables in this module to the XDATA ram. I don't want to modify each variable to XDATA one by one, so is there any simple way to implement this requirment?
Your kind support is highly appreciated!
Thanks & Regards aolin
Thanks for everybody's effort here! I tried the SMALL memory model to compile the add-on module, but fail in linking stage, the DATAGROUP for auto, local variables is too large to fit in the 8052 internal memory! So I have to give up the SMALL mode and use the LARGE mode. The cost is the code size is arround 8KB bigger than the SMALL mode!
You can still use the small memory model, just as long as you have a couple of larger memory variables that you can specifically force out by specifying XDATA.
The difference between the memory models is not what memory areas that can be used, but what memory areas that are used by default.
"So I have to give up the SMALL mode and use the LARGE mode."
Can you not, as I just suggested, edit the type definitions to include the 'xdata' keyword?
For example:
#if defined _MSC_VER // These definitions when using MSVC typedef unsigned char U8; /* Unsigned, 8 bits */ typedef signed char S8; /* Signed, 8 bits */ #elif defined __C51__ // These definitions when using Keil C51 #define U8 xdata unsigned char U8 /* Unsigned, 8 bits in XDATA */ #define S8 xdata signed char U8 /* Signed, 8 bits in XDATA */ #else #error Unknown compiler #endif
then you could continue to use the SMALL model...
I take Andy's suggestion one step further, and actually have different files for different compilers. Rather than run down a series of #ifs, the build system (make, jam, uVision, whatever) just includes only the header appropriate to the tools in use. No #if maintenance required.
Presumably the OP is in control of his build system, and can perhaps substitute the "local conventions typedefs" file for the one used by the owners of the code that can't be changed.
"I take Andy's suggestion one step further, and actually have different files for different compilers."
Ah yes - you've mentioned it before. It sounds a jolly good idea - I might change to doing it that way...
I would still include a check in each file to prevent it being "accidentally" used with the wrong compiler; eg,
// c51.h #ifdef __C51__ // C51 stuff here #else #error Wrong compiler! #endif // end of file