How to force location of variable in memory
-
- Active Member
- Posts: 55
- Joined: Wed Jan 05, 2011 2:15 pm
How to force location of variable in memory
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..
-
- Experienced Member
- Posts: 69
- Joined: Mon May 17, 2010 10:19 am
The linker can't do that. You can use the assembler to force things onto particular boundaries but not to specific addresses.
Why 0x14000?
Why 0x14000?
-
- Respected Member
- Posts: 296
- Joined: Thu Dec 10, 2009 10:33 pm
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.
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.
-
- Respected Member
- Posts: 259
- Joined: Thu Sep 16, 2010 9:15 am
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!).
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!).