Shop OBEX P1 Docs P2 Docs Learn Events
Arrays, Aliases, and Modifiers, Oh My! — Parallax Forums

Arrays, Aliases, and Modifiers, Oh My!

CliffSCliffS Posts: 12
edited 2010-06-20 21:25 in BASIC Stamp
This has to be easy, but I'm baffled.

I'd like to set up an 8-word array which will be aliased into a 128 bit array, and also be aliased into (6 different words and 4 different bytes)
Here's my pseudocode:

Galaxy VAR Word(8) ' ok, here's my 8 word array. There are 8 Galaxies: Galaxy(0), Galaxy(1) ... Galaxy(7)

Planet VAR Galaxy.BIT0 ' now I have 128 planets. So Planet(19) is the 4th bit in Galaxy(3) no problem so far...

' the following lines don't fly. What's wrong with 'em???

RedStar VAR Galaxy(0) ' make Red Star to be a 16 bit fullword that is the same as Galaxy(0)
OrangeStar VAR Galaxy(1) 'make Orange Star to be a 16 bit fullword that is the same as Galaxy(1)
YellowStar VAR Galaxy(3) ' make Blue Star to be a 16 bit fullword that is the same as Galaxy(3)

WhiteDwarf VAR Galaxy(7) ' make WhiteDwarf to be a 8 bit byte that maps into HIGHBYTE of Galaxy(7) [noparse][[/noparse]How do I tell the complier that WhiteDwarf is a byte???]
BrownDwarf VAR Galaxy(7) ' make BrownDwarf to be an 8 bit byte that maps into LOWBYTE of Galaxy(7)

' and, of course, OrangeStar would be the same as planet(8), Planet(9), Planet(10) ... Planet(15)
' WhiteDwarf would be the same as planet(28) to Planet(35)

How to do it?

Cheers to all,
-Cliff

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-06-19 20:17
    You are better off starting with an implicit rather than explicit array. Always more flexible.

    RedStar VAR Word ' make Red Star to be a 16 bit fullword that is the same as Galaxy(0)
    OrangeStar VAR Word 'make Orange Star to be a 16 bit fullword that is the same as Galaxy(1)
    YellowStar VAR Word ' make Blue Star to be a 16 bit fullword that is the same as Galaxy(3)
    ' ... and so on
    BlackStar VAR Word ' this is the 8th word defined
    
    Galaxy  VAR RedStar   ' same memory location as RedStar
                                   '  but can address successive words as  Galaxy(idx) for idx=0..7
    
    Planet VAR RedStar.bit0  ' can address as Planet(idx) for idx=0 .. 63
    
    Dwarfs VAR RedStar.byte0 ' can address as Dwarfs(idx) for idx=0 to 15
    
    BrownDwarf VAR BlackStar.byte0   ' =Dwarfs(14)
    Whitedwarf VAR BlackStar.byte1    ' =Dwarfs(15)   or =BrownDwarf(1)
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • CliffSCliffS Posts: 12
    edited 2010-06-19 20:24
    Many thanks Tracy...

    So unless you tell the compiler otherwise, it assigns memory in the order implied by the program's source code.

    Hmmmm...

    Cheers,
    -Cliff
  • W9GFOW9GFO Posts: 4,010
    edited 2010-06-20 21:25
    CliffS said...
    So unless you tell the compiler otherwise, it assigns memory in the order implied by the program's source code.

    I think it assigns memory locations in order of size. Words first, then Bytes, Nibbles and finally Bits.

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.
Sign In or Register to comment.