I’m not sure how the databank addresses relate to the C variables.
In C when you declare an array you are really allocating a portion of memory and storing the start of that portion in the array variable. So:
unsigned char b[200];
means “allocate 200 bytes, and store the address of the start of that newly allocated block in b”.
So b is really just a pointer to a memory location. So the linker script above is just allocating the memory and giving it a name, but not doing it in C:
DATABANK NAME=gpr345 START=0x300 END=0x5FF
Obviously the harder part is that you have to explicitly give it the start/end positions, which if you use C syntax to allocate the block the compiler/linker does it for you.
Just to complete the example: when you access an array element, like
b[200] = 5;
You are really saying “add 200*sizeof(any array element in b) to the address stored in b, and store 5 at that memory address”.
Ahhh lovely now I can relate it to some of the ASM I know (Which is probably what the compiler makes the arrays into heheh)
The thing I really don’t get is how our array called ‘b’ matches up with the linker script, I mean, do we need to add the array’s name and memory space to the linker every time we create an array?
Today I’ve got that “I should have stuck with ASM” feeling
Although it’s interesting having read that such a possibility exists, I would leave my fingers from it. This sounds really dangerous, because it contains several traps to step into if you’re changing smth later…
If you really need more than 256 array elements, it might be of wiser to group the items and use some #defines
(Besides 256 AINs? 256 LED’s? No… maybe 256 DIN’s? Man, that seems like button-hell ;D I just counted 110 keys on my computer’s keyboard… )
The thing I really don’t get is how our array called ‘b’ matches up with the linker script, I mean, do we need to add the array’s name and memory space to the linker every time we create an array?
Apparently only when it’s >256 bytes (or maybe 256 elements, you’d have to try)
Good news guys, I’ve been doing some experimentation and have figured out what’s going on with all this drama about large data storage and arrays. I’ll write a documentation on the wiki shortly with full instructions.
Before I do, I just need to find out some info about memory use on the 4620 so I can document that too… But that’s one for another thread.
In short: Arrays can be addressed with >8bit indexes, no problem, but they attempt to allocate more ram than is available. The symbolic name trick from vangelis (and the sdcc manual) posted previously works like a charm
Well, a lot of us use those threads as reference points, especially a good newbie doing a search to find out info. Several of them are linked from wiki articles too… If I put this info in one thread, they may miss it, so it’s in the threads where it was said that the limit was 8 bit, as an update to the existing doco.
Sorry for the annoyance, but it’s important, for future reference