Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

Placing variables in memory

Hi,

I'm developing an application with CyclloneII and I have the issue below:

is there a way to place a variable at particular address in memory, something like the "_AT_" flag of some micros?

Example:

alt_u8 DummyByte ...something here.... 0x0080000:

Note that i want to put the variable in some fixed location, not in some section like .text,.rodata et., or provided the allocation in a section, I want the freedom to choose the address within that memory.

Thanks in Advance

Emme

6 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    You can use register variable of NIOS cpu.

    Here is the syntex of it.

    register unsigned int temp_data2 asm("r12");

    by this you have a freedom to choose the memory location of your specific variables.

    I hope this would be sufficient help for you.

    Regards,

    slsnios
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    I'm not sure if I am on the right track, if I "put" variable in the register how can I bond its address?

    More, I've many variables to place at fixed address ...

    Emme
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Emme,

    > Note that i want to put the variable in some fixed location, not in some section

    > like .text,.rodata et., or provided the allocation in a section, I want the freedom to

    > choose the address within that memory.

    The compiler puts variables, code, etc. into sections ... there's no choice in this matter other than

    specifying a compiler output section ... so, if you want to do things at run time, you'll have to use a

    pointer:

    alt_u8 *pDummyByte = (alt_u8 *) 0x0080000;

    or something similar.

    Regards,

    --Scott
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Scott,

    I see...

    Thanks a lot, now I`m using pointers and things are going well.

    Best regards,

    Emme.

    --- Quote Start ---

    originally posted by smcnutt@Nov 21 2006, 05:12 PM

    hi emme,

    > note that i want to put the variable in some fixed location, not in some section

    > like .text,.rodata et., or provided the allocation in a section, i want the freedom to

    > choose the address within that memory.

    the compiler puts variables, code, etc. into sections ... there's no choice in this matter other than

    specifying a compiler output section ... so, if you want to do things at run time, you'll have to use a

    pointer:

    alt_u8 *pdummybyte = (alt_u8 *) 0x0080000;

    or something similar.

    regards,

    --scott

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=19563)

    --- quote end ---

    --- Quote End ---

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    originally posted by smcnutt@Nov 21 2006, 10:12 AM

    the compiler puts variables, code, etc. into sections ... there&#39;s no choice in this matter other than

    specifying a compiler output section ... so, if you want to do things at run time, you&#39;ll have to use a

    pointer:

    alt_u8 *pdummybyte = (alt_u8 *) 0x0080000;

    or something similar.

    regards,

    --scott

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=19563)

    --- quote end ---

    --- Quote End ---

    Many embedded C compilers have the extensions like Emme has mentioned (_AT_) to not only allow usage of the memory block but make the access fast.

    Using "at" lets you avoid indirect addressing in case your main memory is slow.

    Let&#39;s say you want to put some data buffer for an isr in a on-chip memory to avoid using slow external ram bus - how would you do it with your method?

    To resolve pointer you would still have to access it located in the external ram, so you would not save any time doint this...

    It would be great if the gcc compiler implementation for Nios could be extended with some typical embedded features like "at" directive...
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    > Let&#39;s say you want to put some data buffer for an isr in a on-chip memory to avoid using slow

    > external ram bus - how would you do it with your method?

    The same way ;-)

    > To resolve pointer you would still have to access it located in the external ram, so you would

    > not save any time doint this...

    This is an optimization issue -- even -O1 will avoid this, and keep the pointer in a register.

    > It would be great if the gcc compiler implementation for Nios could be extended with some

    > typical embedded features like "at" directive...

    The section attribute handles many of these situations. A linker script can handle the rest -- using

    script defined variables, for example,

    Regards,

    --Scott