Shop OBEX P1 Docs P2 Docs Learn Events
arrays — Parallax Forums

arrays

Lee MarshallLee Marshall Posts: 106
edited 2007-08-05 00:45 in Propeller 1
hi, i want to be able to access the data in an array in asm, it seems the next logical step would be to find out how arrays are actually stored in memory, i assume it will be something like:

BASE ADDRESS: LENGTH OF ARRAY
BASE ADDRESS+1: ARRAY DATA 0
BASE ADDRESS+2: ARRAY DATA 1
etc...

so, how are arrays stored?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Propeller is the best micro!

srry if im sound a little unprofessional sometimes, im 15.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-04 03:02
    If you're talking about Spin arrays stored in the hub ram, there's no length stored, just the array elements.

    Arrays in Spin are fixed length, so the length doesn't have to be stored with the array.
  • rjo_rjo_ Posts: 1,825
    edited 2007-08-04 03:21
    I don't know if this will help. But I asked for help with arrays. My question was: Could someone post a complete example that does nothing but index through a dat table and pass the values back to a Spin array... ?

    Look at Ariba's (Andy's) response.

    http://forums.parallax.com/forums/default.aspx?f=25&m=190445&g=190993#m190993
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-04 08:33
    There is no such thing as an "array" in Spin ; it is just a concept to simplify memory allocation and some syntactic sugar to allow to write something as
    y := arr[noparse][[/noparse] x ]
    


    In this example the compiler will - through the declaration - know the length of the elements in "arr" (1, 2 or 4) and adjust the de-referencing accordingly. The above line - given that arr is declared as LONG - is absolutely equivalent to
    y := long[noparse][[/noparse] @arr+4*x ]
    



    The following example will give you all required information
    CON
      _CLKMODE  = XTAL1 + PLL8X  ' Hydra Settings
      _XINFREQ  = 10_000_000
    VAR
      LONG arr [noparse][[/noparse] 2 ]
    PUB main|x
     x := 1
     arr[noparse][[/noparse] x ] := 4711
    
     IF LONG[noparse][[/noparse] @arr+4*x ] == 4711
        outa[noparse][[/noparse] 0 ] := dira[noparse][[/noparse] 0 ] := 1
     REPEAT
    
    

    Post Edited (deSilva) : 8/4/2007 8:44:56 AM GMT
  • hippyhippy Posts: 1,981
    edited 2007-08-04 14:49
    deSilva said...
    There is no such thing as an "array" in Spin ; it is just a concept to simplify memory allocation and some syntactic sugar to allow to write something as
    y := arr[noparse][[/noparse] x ]
    

    The Spin bytecode does implicitly support Array Indexing. Spin code such as ...
    a[noparse][[/noparse] 1 ] := b[noparse][[/noparse] 2 ]
    


    translates to bytecode as ...
    push 2
    push b[noparse][[/noparse]]
    push 1
    pop  a[noparse][[/noparse]]
    


    Whereas ...
    LONG[noparse][[/noparse] @a+(1*4) ] := LONG[noparse][[/noparse] @b+(2*4) ]
    


    should translate as ...
    push b+8
    pop  a+4
    

    Post Edited (hippy) : 8/4/2007 2:59:17 PM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-04 16:06
    So much the worse smile.gif
  • BergamotBergamot Posts: 185
    edited 2007-08-04 20:52
    hippy said...
    deSilva said...
    There is no such thing as an "array" in Spin ; it is just a concept to simplify memory allocation and some syntactic sugar to allow to write something as
    y := arr[noparse][[/noparse] x ]
    

    The Spin bytecode does implicitly support Array Indexing. Spin code such as ...
    a[noparse][[/noparse] 1 ] := b[noparse][[/noparse] 2 ]
    


    translates to bytecode as ...
    push 2
    push b[noparse][[/noparse]]
    push 1
    pop  a[noparse][[/noparse]]
    


    Whereas ...
    LONG[noparse][[/noparse] @a+(1*4) ] := LONG[noparse][[/noparse] @b+(2*4) ]
    


    should translate as ...
    push b+8
    pop  a+4
    


    But why? If I understand you correctly, this makes the SPIN interpreter more complex, with no major benefits in terms of array access.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-04 21:46
    This has certainly gotten fairly far afield. Mr Crowley, has your question been answered? Did rjo_'s link help?
  • hippyhippy Posts: 1,981
    edited 2007-08-05 00:01
    Bergamot said...
    ...But why? If I understand you correctly, this makes the SPIN interpreter more complex, with no major benefits in terms of array access.
    It helps when an array index is something other than a constant, the bytecode implies TOS should be popped and added to the variable address which is then pushed.

    Without that mechanism, the index would need pushing, the array's base address would need pushing, both added, and then the TOS would need to be popped and used as the address to actually load from. So this is very efficient, and not overly complicating for an interpreter.

    It's not an efficient mechanism for constant array indexes, but that's down to the Spin compiler not optimising.
  • Lee MarshallLee Marshall Posts: 106
    edited 2007-08-05 00:45
    Somebody said...
    Mr Crowley, has your question been answered? Did rjo_'s link help?

    yes, and yes, thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Propeller is the best micro!

    srry if im sound a little unprofessional sometimes, im 15.
Sign In or Register to comment.