PDA

View Full Version : memory storage order/arrangement



Bobb Fwed
07-24-2009, 02:32 AM
I have some longs and words declared in a var block:


long var1
long var2
long var3[ 4 ]
word var4[ 8 ]
word var5[ 8 ]



now I would think that var5 being a eight-length word is the same thing as a four-length long, but when I try to access the expected addresses in PASM (referenced from var1's location as based in PAR), it doesn't seem to line up.... I haven't messed with exactly how it isn't lining up, but maybe someone can tell me before I spend time rediscovering the wheel. Does the compiler (or other) rearrange word and long (and byte for that matter) declarations or something weird like that?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!

mpark
07-24-2009, 03:16 AM
Yes. All the long vars are grouped together first, then the word vars, then the byte vars. This reduces wasted space and increases programmer confusion.

MagIO2
07-24-2009, 03:52 AM
The example as given above should work. My guess is that you have other longs which you did not mention. These will be rearranged by the compiler as mpark already explained. There are several possibilities to do what you want:

1. Why not create a long array with 14 longs (long allvars[14])? You can access var1, var2 and var3[] very easyly using dedicaded index ... maybe define this in the constant block as VAR1, VAR2 and VAR3. Then you can write allvars[VAR1] .. allvars[VAR3 +2] ... for example ..
The words can be accessed by word[@allvars+VAR4]

2. You can create the vars in the dat section instead. There the data is not reordered. But you have to take care of the alignment by yourself. Doing something wrong here can lead to hard to find bugs.

Bobb Fwed
07-24-2009, 04:32 AM
mpark said...
Yes. All the long vars are grouped together first, then the word vars, then the byte vars. This reduces wasted space and increases programmer confusion.

Yes, I see the problem now, I was altering longs to bytes at the lop of my list and screwing things all up.

Any idea why I am having problems switching between long[ 4 ] and word[ 8 ] at the end of my var list?

What about, when one object declares longs/words/bytes...are those mixed in with other objects' variables? Could that be causing my above problem?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!

Bobb Fwed
07-24-2009, 04:43 AM
I decided not to mess with it. It was only a matter of 15 longs, and doing it any other way than I am right now will slow down some of the very basic actions in my object. I'll just stick with all longs.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!