This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GH6PM: Question on use of assembly .data section for TM4C123

Part Number: TM4C123GH6PM

Hello, I have been reading about the functioning of the assembler/linker and something is unclear to me - I don't understand the use of the .data section.

Assuming you're running a program without an OS, the program is saved to internal flash and run from there - there is nothing to pre-load values into SRAM. So what function does the .data section serve? Where/how is it used? Does the assembler write a separate initialization routine?

I understand its point if you have a separate OS or loader which loads the program into memory and populates SRAM but if your program is stand alone, how does it work?

Thank you.

  • Hi,

    The .data section is for initialised variables - they can be present in every C/C++ program, with or without an underlying OS. The linker creates the section and at run time (startup file in Tiva), the section is copied from flash to ram. To find out more about all sections in a C program, see this TI document. Take into account there is a similar document related to the ARM C compiler. 

    As friend cb1 suggested in your previous post about .asm, the J. Yiu  book is also a good source of information. Also, Valvano books.

  • Good data/job by friend Petrei - as always.

    He's made the point that I would have as well - yet would it not be most efficient for you to create a "blend" of (both) "C" and "ASM" - and then "exploit" the benefits of both?

    As you have an operational MCU board - nothing prevents your "free-form" experimentation - so that the (vastly under-served) intricacies of ASM may be "teased out." You may also visit the ARM site - determine (their) level of interest in ASM.

    You've "culled yourself from the programming herd" - even vendor experts may not have the "instant fluency" w/ASM - which is (daily) "so on display" w/the mainstream "C." You may wish to give that good consideration - swimming against a strong tide is not easy - nor efficient - thus rarely recommended! (and still - we know not your motivation to use ASM...)
  • Hmm, this is what I am confused on - suppose I am writing everything in assembly, does the assembler or linker add its own initialization routine for the .data section? Does the processor automatically copy the section into ram without an explicit copying function?
  • You have control of how the .data section is created in assembly. You can allocate the .data to the RAM using the linker.  For details, please refer to the assembler userguide.

    Below is the default memory allocation. Normally you would allocate .text, .const, .cinit and .pinit to the Flash and .data, .bss, .system and .stack to the RAM.