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

How to place a "short string" into [RO-DATA] section, but not in [RO-CODE(inc. data)] section?

I use Keil uVision4 to build my project.

Here is my test C code:

void func(void)

{

    //do something

    printf("I hope to be recognized as RO-DATA!\n");

}

But assembler code is below. As u see, the string was put into RO-CODE section as inline data!

I realllllllllllllly want to know How to place a "short string" into [RO-DATA] section, but not in [RO-CODE(inc. data)] section?

Thanks!

------------------------------------------------------------------------------------------------------------------

     func

         0x00002c44:    b510        ..      PUSH     {r4,lr}

         0x00002c46:    a013        ..      ADR      r0,{pc}+0x4e ; 0x2c94

         0x00002c48:    f000fc9a    ....    BL       printf ; 0x3580

         ;;  some other codes for RO-CODE section

     $d

         ;;  the string is here !

         0x00002c94:    6f682049    I **    DCD    1869094985

         0x00002c98:    74206570    pe t    DCD    1948280176

         0x00002c9c:    6562206f    o be    DCD    1700929647

         0x00002ca0:    63657220     rec    DCD    1667592736

         0x00002ca4:    696e676f    ogni    DCD    1768843119

         0x00002ca8:    2064657a    zed     DCD    543450490

         0x00002cac:    52207361    as R    DCD    1377858401

         0x00002cb0:    41442d4f    O-DA    DCD    1094987087

         0x00002cb4:    0a214154    TA!.    DCD    169951572

         0x00002cb8:    00000000    ....    DCD    0

------------------------------------------------------------------------------------------------------------------  

Parents
  • As the previous reply points out, you have to declare your string separately to place it in the data section. In the following example, the string will be placed in the RODATA section.

    const char string[]="string";

    void func(void)

    {

    printf(string);

    }

    Hope this helps.

    Chris

Reply
  • As the previous reply points out, you have to declare your string separately to place it in the data section. In the following example, the string will be placed in the RODATA section.

    const char string[]="string";

    void func(void)

    {

    printf(string);

    }

    Hope this helps.

    Chris

Children
  • i thought i must found another way because we are accustomed to use printf like this :

    printf("put the str here directly");

    thank u all the same

  • I'm glad you found the response useful. You are right that it is more usual to place the literal as one of the arguments to the printf function call and this is what most people do. As you have discovered, this will have the effect of placing the literal in the code section so it can easily be accessed at run-time without a linker fix-up.

    I am slightly curious as to why you want to place the literal in the data section. Do you have a specific requirement which means that you need to do this?

    Chris