Skip to main content
Knowledgebase
Home
Renesas Singapore - Knowledgebase

Is there any way to refer the addresses within the file of C source code?

Latest Updated:02/27/2015

Question:

Is there any way to refer to the addresses where sections start and end from within a file of C source code?

Answer:

References to the addresses can be made by creating and calling an inline assembly-language function which acquires the addresses of sections.
The following reserved symbols are automatically generated in linkage processing.

  • A symbol having the address where each output section starts as its value
  • A symbol having the first address following the end of each output section as its value

A symbol formed by appending the prefix "__s" to the name of an output section has the value of the address where the section starts. A symbol formed by appending the prefix "__e" to the name of the output section has the value of the first address following the end of a section. These symbols are only accessible from the assembler.
Accordingly, create and call an inline assembly function, which transfers these symbols to the r10 register in which the return value of the function is stored, in your C source code.

Example 1: Defining an inline assembly function that acquires the address where the .data section starts

   ----------------------------
   static unsigned long start_addr(void) {
       mov #__s.data, r10
   }
   ----------------------------

Example 2: Storing the address where the .data section starts in variable "addr"

   ----------------------------
   unsigned long addr;
   …
   addr = start_addr();
   ----------------------------
Suitable Products
C Compiler Package for RH850 Family