Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

where are constants string literals stored in memory of microcontroller ?

Status
Not open for further replies.

ahmedsaber

Junior Member level 1
Joined
Mar 11, 2013
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Al Jizah, Egypt
Activity points
1,449
microcontroller flash memory divided into
code segment // to store the code itself
.rodata segment
startup segment // to store the startup code

my question is

where are the locations of the literal string like

if i define char array[100]= " hello every one ";

also where the constant variables like const int var=100;
 

In C language, you can store values used as constant in program either in program memory (flash, prom, ...) or in data memory (RAM), being the only syntactical difference, the addition of the const, let's say, 'modifier'. When stored in RAM you cannot change their values, otherwise will be not constants. There is no distinction by the compiler about the type of variable ( string, int, ... ).
 

@andre_teprom

regarding Const variables : i know what you wanna say that we can with syntax store any variables in any memory
with using keyword eeprom and flash at the variable declaration but this answer deviate little away from my question

const int var=10; question is : is var stored in .rodata in flash ? at run time is it will be copied to Ram or will be accessed also from flash ?
at all it willn't be changed
 

where are the locations of the literal string
Since you are writing C, the linker is the tool that decides where the variables will be stored, unless you force variables or functions to be stored in a specifc address. I would suggest not to try this, unless you are an experienced user of the IDE and the compiler you are working with. In any case, you have the lst and map files to access information like this.

const int var=10; question is : is var stored in .rodata in flash ?
It depends on the compiler. Other compilers store "const" variables in flash and other compilers store it in RAM, but forbid you to edit those RAM values.

at run time is it will be copied to Ram or will be accessed also from flash ?
Even if you store data to flash but never access them, then a decent compiler will not even store this anywhere. If you access them, it would somehow be written in RAM. Because even if you don't load this manually (ie int var2=var;), you will somehow access it (ie if (var2==var){var2=1;}). So in assembly level, the value of var must be loaded to a register, in order to achieve this conditional branching. I have never heart of MCU architectures that carry such comparing procedures using flash. On the other hand, I am not an experienced user in assembly, so if someone knows an MCU architecture that does that, I will be glad to know.
 

where are the locations of the literal string like

if i define char array[100]= " hello every one ";

also where the constant variables like const int var=100;

It seems clear that the above variable 'array' should be placed at .data section, whereas above variable 'var' should be placed at .rodata section. Are you aware that the const modifier is what allocate a variable in the read only data section ?
 
The question can't be answered without referring to a specific microcontroller and compiler.

The type qualifier const doesn't imply an assignment to a particular memory region by C specification. It only says that the object is assumed read-only.

Some embedded compilers automatically assign const objects to flash memory if applicable. Others have additional qualifiers or attributes for this assignment and place const objects in initialized RAM if not commanded otherwise.

An important point is if the microcontroller architecture allows access of flash as data memory or if special table read instructions must be performed to read flash (as for PIC16/18).

You really need to ask your question more specifically.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top