Hello...
Currently I am using a header file that contains imported variables/functions/arrays at specific addressing. This is not ideal but it is the only workaround I have for my project. Now I'm trying to modularize my code therefore I am not able to include this header file in all modules as it will cause linker errors. I am using extern to get around that for var declarations. I was wondering if there is any way to import #define 's other than simply copying them over to each module. The following super rough code is to elaborate what I mean.
/* mem_import.h */ #ifndef MEM_IMPORT_H #define MEM_IMPORT_H volatile int flags _at_ 0; #define flags_array ((uint8_t xdata *)(0x0080)) #define operate_flags() (*(void (code *)(void))(0x00ff))() #endif /* main.c */ #include "module_a.h" #include "module_b.h" #include "mem_import.h" /* module_a.c */ // #include "mem_import.h" extern volatile int flags; /* module_b.c */ //#include "mem_import.h" extern volatile int flags;
I would like to be able to use the 'operate_flags()' and 'flag_array' macros in each module. Is there any way to do this that doesn't involve including the mem_imports.h or simply copying it over where ever it's needed. The reason I don't want to copy it over is I will loose the modularization because of the specific addressing.
Thanks for any help in advance and let me know if more clarification is needed.
Take a closer look at the instruction set of the processor, and you would see that the processor does not have any great _general_ instructions for indurect addressing.
That also affects the ability to use a _real_ stack with indirect addressing of parameters and local variables relative to a base pointer. Which makes the C51 compiler convert parameters and local variables into reused global variables. And that optimization requirs the compiler/linker to know exactly what functions that can call other functions - how else would the compiler/linker know which two different local variables that can share the same global memory address?
The 8051 architecture is extremely hostile for use with high-level languages.
We agree with the posts warning you of the indirect addressing problems of the 8051. Look at the PK51 Linker Manual and pay close attention to the OVERLAY directives and their examples.
Bradford
www.keil.com/.../search.asp
Thanks for the info and link.
Cheers