How to force location of variable in memory

Technical questions regarding the XTC tools and programming with XMOS.
GerhardNorkus
Active Member
Posts: 55
Joined: Wed Jan 05, 2011 2:15 pm

How to force location of variable in memory

Post by GerhardNorkus »

How do I force a variable to be at a specific location in memory? For example, say suppose I want an array of chars (size=16384 chars), what to I do to force the xmapper to set this for me? I am trying to create a circular buffer accepting data at highest possible data rate, and I need the result of the following line to be such that the result of ldaw r0, dp[FIFOArray] is r0=0x00014000. In other words, I want FIFOArray[16384] to start at 0x00014000 in memory..


m_y
Experienced Member
Posts: 69
Joined: Mon May 17, 2010 10:19 am

Post by m_y »

The linker can't do that. You can use the assembler to force things onto particular boundaries but not to specific addresses.

Why 0x14000?
Heater
Respected Member
Posts: 296
Joined: Thu Dec 10, 2009 10:33 pm

Post by Heater »

Good question. Why do you want to do this and why that address.

Normally there is no reason to do such a thing unless you are fitting your program to some odd memory map or interfacing with some memory mapped hardware.
ale500
Respected Member
Posts: 259
Joined: Thu Sep 16, 2010 9:15 am

Post by ale500 »

There is a trick you can use but you will waste memory and it may not even end up where you want it exactly but... if you make the array 32767 bytes long instead it will contain a 16k boundary and maybe two :) but which one.
We still want to know why that address... if it is because of some alignment you need... you don't. The only alignment is to a word boundary. And if it is because of a 16 bit offset... it is 16 bits and thus any memory location is as good as the next one.

Now... I think there is another way... if you embed the array into the code and as the code starts at 0 you may guess how much code and filling you need to get the buffer you need... bit of guesswork but it may work better than the other method (you use an assembly source file for that!).