Shop OBEX P1 Docs P2 Docs Learn Events
memory storage order/arrangement — Parallax Forums

memory storage order/arrangement

Bobb FwedBobb Fwed Posts: 1,119
edited 2009-07-23 20:43 in Propeller 1
I have some longs and words declared in a var block:
long var1
long var2
long var3[noparse][[/noparse] 4 ]
word var4[noparse][[/noparse] 8 ]
word var5[noparse][[/noparse] 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!

Comments

  • mparkmpark Posts: 1,305
    edited 2009-07-23 19:16
    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.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-07-23 19:52
    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[noparse]/noparse]14])? You can access var1, var2 and var3[noparse][[/noparse very easyly using dedicaded index ... maybe define this in the constant block as VAR1, VAR2 and VAR3. Then you can write allvars[noparse][[/noparse]VAR1] .. allvars[noparse][[/noparse]VAR3 +2] ... for example ..
    The words can be accessed by word[noparse][[/noparse]@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 FwedBobb Fwed Posts: 1,119
    edited 2009-07-23 20:32
    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[noparse][[/noparse] 4 ] and word[noparse][[/noparse] 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 FwedBobb Fwed Posts: 1,119
    edited 2009-07-23 20:43
    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!
Sign In or Register to comment.