We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Please let me know whether the size of .bss section should be included in ROM size or in RAM size ? In other words : where does the .bss section lay? In ROM or in RAM? Thanks in advance
To be picky, Keil C doesn't have a "bss section". That name comes from the old Unix assembler, and you won't find a "text", "data", and "bss" in the segment names generated by the Keil tools. But pedantry aside, the bss section traditionally is that section that contains all the uninitialized variables, which (according to spec) must be set to all zeros before main() begins. Since you know the value of every byte in this section (0), it's generally a waste of space to store a whole bunch of zeros in your code image (probably a ROM, in our case). Instead, the startup code will usually initialize a chunk of memory to all zeros when the program begins. The zeros don't take up ROM space, but the code to initialize the memory does. (You could think of that as a form of data compression, if you like.) The variables themselves must live in RAM, if they're variable. Keil (and any decent embedded compiler) will also let you declare constants that remain in ROM, without being copied to RAM. See the code keyword in the discussion of memory spaces in the manual. You can find the code that performs the memory initialization in STARTUP.A51. If you have initialized file-scope variables (the "data" section), these values must be kept in ROM, and copied to RAM before main begins. INIT.A51 does this task. Note that with the Keil tools, these bits of code are optional. Embedded systems often need better control over their startup and initialization (and restarts and re-initialization) than the traditional C behavior, which is more oriented for convenience in slapping together a command-line-driven user program.
"Keil (and any decent embedded compiler) will also let you declare constants that remain in ROM, without being copied to RAM. See the code keyword in the discussion of memory spaces in the manual." Indeed, and you can locate them at a specific address using the _at_ keyword. If you do this, however, Keil does not allow you to initialise them rendering them somewhat useless. Stefan