We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Is there any way to declare a symbolic constant as 'an external number' in Keil C51 source code so that the compiler generates object file using instructions with # symbol prefix (e.g. mov r0,#symbol) and therefore the value of this symbol can be supplied on the linker level (from another obj file, where the symbol is given a value and declared as public) ? (Including file with #defines into the source code does not solve the issue - symbols must be defined at the compile time.) Note: in assembler it is easy ... file1.a51 : (file1.obj defines particular values of needed constants for a concrete project)
... public SYMBOL SYMBOL equ 5 ...
... extrn number (SYMBOL) ... mov a,#SYMBOL ...
Since Keil is a 'C' compiler the point is moot. In the '167 and '251 tool chains there is an 'ASSIGN' command for the linker. I'm not sure if it is in the '51 tools. Usage is; 'C' file
extern unsigned char symbol_Var; { ... unsigned int destination_Var; destination_Var = _sof_( symbol_Var ); ... }
L167 ... ASSIGN( 'symbol_Var' (0x1234))
MOV R4, #1234h
I have seen that sort of trick used by a Client before; not only was it non-portable, but it was also very poorly documented! In the particular case I'm thinking of, the Linker did assign a symbol address rather than a value - which just added to the confusion, as the source code wanted a value! This particular Client also used the cunning trick of passing their Linker command file through the 'C' preprocessor before actually giving it to the Linker - thus enabling them to use 'C'-style symbolic definitions, instead of "magic numnbers" in the Linker command file! This was also undocumented and, needless to say, the whole tangled web took several days to unravel! What I'm saying is: if you really must resort to such tricks, please ensure that they are lucidly documented - preferably as comments directly in the files, rather than some separate "document" which will just get lost and/or out of date. But then, if people did that, they wouldn't need to hire people like me to sort it out later ... ;-)