Hello,
I am working on a program where I need my variables to be placed sequentially in ram. How can I do this?
Currently I have them defined in the order that I wish for them to appear in the RAM, and for the most part this works. However, a few variables are scattered into other locations. I know this because I have checked their location using the Keil ULINK JTAG debugger.
Here is an example showing how I have my variables defined:
vars.c:
char MemStart; char Mem01; char Mem02[5]; char Mem03[10]; char Mem04[17]; char Mem05[15]; char Mem06; char Mem07[3]; char Mem08; char Mem09; ... char MemEnd;
MemStart is placed in address 0x400013FE, MemEnd in 0x4000149A;
And then: Mem01 0x400013FF --which seems correct Mem02 0x40001400 -- again, this seems correct Mem03 0x40001405 -- again, this is correct Mem04 0x40004C67 --- This is definitely not what I want!
Any ideas what I can do about this?
I am using the NXP2378 MCU, Keil uVision 3.51, RVMDK 3.05a.
Thanks! Eric
The only standard means of keeping data object in a particular order is to encapsulate them in a structure.
So there isn't a compiler/assembler directive that will tell Keil to assign ram locations sequentially for this chunk of code?
Thanks for your reply! -Eric
"So there isn't a compiler/assembler directive..."
That, I don't know that answer to. I seem to recall one for C51, but I don't know about your toolchain. When I said "standard", it was in the context of a means provided by the language, not the tools.
As Dan says, putting them in a structure would be the standard, portable way to do it - independent of any specific tool features.
Any particular reason why you'd prefer not to use a structure?
If you're happy to use assembler, you may well find that the assembler does guarantee to keep them in order - check in the Manual