Technical Support

C51: ABSOLUTE FUNCTION ADDRESS


Information in this article applies to:

  • C51 All Versions

QUESTION

How do I locate a C function at an absolute address? I succeeded in variables using _at_, but it doesn't work for functions.

ANSWER

You must use the BL51 Linker or LX51 Linker to locate functions at fixed addresses. To do so, make a note of the function name and the source file in which it is saved. The compiler creates a symbol name for the function using the following format:

?PR?function_name?file_name

So, the function named func in main.c would have a symbol name of:

?PR?FUNC?MAIN

Everything is uppercase to comply with the OMF51 standard.

There may be derivatives of this naming convention. For example, if the function accepts arguments that can all be passed in registers, the function name is prefixed with an underscore ('_') and the above would be:

?PR?_FUNC?MAIN

You may look in the linker's map file to figure out the symbolic names for your functions.

Once you know the symbolic name, it is a simple matter of telling the linker where to locate it using the CODE directive. For example:

BL51 main.obj code(?pr?func?main(2000h))

Tells the linker to locate the function func at code address 0x2000.

If you use the µVision IDE you may enter the starting address for segments under Project - Options for Target. For the BL51 Linker/Locater enter the following code segment with the address under BL51 Locate - Code. For the LX51 Linker/Locater enter it under LX51 Locate - User Segments:

    ?pr?func?main(C:0x2000)

MORE INFORMATION

  • Refer to CODE in the BL51 User's Guide.
  • Refer to SEGMENTS in the LX51 User's Guide.

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Wednesday, October 04, 2006


Did this article provide the answer you needed?
 
Yes
No
Not Sure