Variable Storage area

Moderator
Amit Chatre wrote:
> Hi,
>
>         I assign a variable int x=55; please tell me storage area in
> memory.

Generate a map-file (-Wl,-Map=mymapfile.map when linking with gcc), it
shows the location.

> if it will store in data memory,please what is the way to store it in
> code memroy?

Test with const int x=55;
Amit Chatre wrote:
> Hi,
>
>         I assign a variable int x=55; please tell me storage area in
> memory.

That depends on the storage class of the variable. Non-static local
variables are stored on the stack so are non-deterministic. Either way
you can determine the address at run-time with &x


>
> if it will store in data memory,please what is the way to store it in
> code memroy?
>
> Thanks,
> Aseem

What is it you are actually trying to achieve. Neither the
compiler/linker not the ARM architecture have any concept of 'code' or
'data' memory, code may be executed from ROM or RAM. Did you simply want
to store the data in read-only memory?

It has been suggested that you use the const keyword, but the compiler
is not obliged to store such data in ROM. The semantics of const is
merely that the code cannot modify the data.

To place variables in specific memory areas in GCC you myst use a
section attribute to place the data in a section defined in the linker
script.
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Variable-Attributes.html#Variable-Attributes

Clifford
OP
Thank you for all this,

Clifford Slocombe wrote:
> Amit Chatre wrote:
>> Hi,
>>
>>         I assign a variable int x=55; please tell me storage area in
>> memory.
>
> That depends on the storage class of the variable. Non-static local
> variables are stored on the stack so are non-deterministic. Either way
> you can determine the address at run-time with &x
>
by using const keyword I'm able to save data in read only memeory.
>
>>
>> if it will store in data memory,please what is the way to store it in
>> code memroy?
>>
>> Thanks,
>> Aseem
>
> What is it you are actually trying to achieve. Neither the
> compiler/linker not the ARM architecture have any concept of 'code' or
> 'data' memory, code may be executed from ROM or RAM. Did you simply want
> to store the data in read-only memory?
>
Actually I wanted to store const defined variables in ROM.
now suppose if I have a variable array of int
const unsigned int i[1024]={
                              ....
                              ....
                           };
then it should be store in flash memroy.

> It has been suggested that you use the const keyword, but the compiler
> is not obliged to store such data in ROM. The semantics of const is
> merely that the code cannot modify the data.
>
> To place variables in specific memory areas in GCC you myst use a
> section attribute to place the data in a section defined in the linker
> script.
> 
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Variable-Attributes.html#Variable-Attributes
>
> Clifford

Again ther is one problem,
how can I define a variable external memroy by default.

means if i defined a variable
const int XL[10];

its memory address would be 0xA0000000.
Please tell me how can I do this?

Or any suggestion or link about memory interfacing and samples codes.
I'm totally new for memory interfacing.....

Thanks in Advance.
Aseem
The answer to your question is as I suggested - use a linker section
attribute.

const unsigned int i[1024] _attribute_ ((section ("ROMDATA"))) =
               {
                  ...
                  ...
               };


const int XL[10] = _attribute_ ((section ("MYLOCATION"))) =
               {
                  ...
                  ...
               };

Note that here ROMDATA and MYLOCATION must be defined in the linker
script. You can define them as absolute addresses or a relocatable
section. As described here:
http://www.math.utah.edu/docs/info/ld_3.html#SEC14

Clifford

Reply

A question of your own? This thread is over 18 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.