Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Placing variables in memory

Altera_Forum
Honored Contributor II
1,755 Views

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
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
531 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
531 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
531 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
531 Views

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 ---  

0 Kudos
Altera_Forum
Honored Contributor II
531 Views

 

--- 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...
0 Kudos
Altera_Forum
Honored Contributor II
531 Views

> 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
0 Kudos
Reply