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

Segment names

In assembly code, it seems common to name segments using question marks. Such as, ?C_C51STARTUP, ?STACK, ?DT?MYFILE, etc. Is there a requirement to do this? If not, what is its purpose? I read TFM, and it says nothing.

  • "I read TFM, and it says nothing."

    Aha - the trick is to read the right bit of the right FM!

    See: http://www.keil.com/support/man/docs/c51/c51_ap_segname.htm

    Names like this usually turn up in code generated by the compiler, or provided to support the compiler.
    The reason for using things like question marks is that it's illegal in 'C' - so the compiler can safely use it and know that there's no chance of it accidentally conflicting with some name that the programmer might dream up!

  • "Is there a requirement to do this? If not, what is its purpose?"

    This is called 'name mangling', and one of its purposes is to avoid namespace conflict in the link stage.

    It also follows a naming convention that the C compiler adheres to, and is internally used by the compiler to describe the various memory allocation segments. If you need to write assembly functions to access C declared data objects, you can use the mangled segment names to map to C variables with proper memory type qualifiers.
    You can also declare data in ASM using the proper segment names and access those objects as C 'extern' variables, declared with the proper memory type qualifiers.