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

Any way for declaring symbolic constants as an external number in C51 source code ?

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
...

file2.a51 : (file2.obj can be stored in a library being 'universal' and the SYMBOL value will be supplied by linker)

...
extrn number (SYMBOL)
...
  mov  a,#SYMBOL
...

Parents Reply Children
  • Hi Andrew,
    "I don't think so..." - probably you are right (what a pity :-), I've thought it as well but I'm still not sure. In my opinion, the linker does not deal with addresses but with "numbers" associated with attributes - data(address), idata(address), xdata(address), ... and number. The attributes provide the linker with necessary information, so it can handle the numbers appropriately and can check their right use as well.
    If there is at least one assembler module with the equ directive used in a project, then you can find lines like:

    VALUE     TYPE      NAME
    ------------------------------
    N:0002H   PUBLIC    PADDRESS
    N:FF90H   SYMBOL    BFUX10000H
    
    in the "SYMBOL TABLE OF MODULE" in the linker listing file (.M51). N means NUMBER.

    Further, in the "INTER-MODULE CROSS-REFERENCE LISTING":
    NAME ....... USAGE   MODULE NAMES
    ----------------------------------------
    ADST_NONE .. NUMB;   REG3_30  BLNK_AD  
    
    I have browsed .M51 files in my "purely C-based" projects and haven't found anything like that there.

    Btw. I have noticed an interesting thing - there is a word NUMBER in the C51.exe file (use an ASCII viewer, e.g. View in XTree) and it is located in a group of words like DATA, BDATA, etc. (looks like group of 'keywords').
    But is there any way to make the compiler to use it ?

    (I'm sorry for such a long 'article')
    Thanks for your interest.

    Stan