Shop OBEX P1 Docs P2 Docs Learn Events
Using arrays in asm — Parallax Forums

Using arrays in asm

kenmackenmac Posts: 96
edited 2008-11-28 10:06 in Propeller 1
Hi folks,
What is the best method of storing/reading data in array elements in asm coding?

kenmac

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Perth, Western Australia
Time Zone = GMT + 8

Comments

  • BaggersBaggers Posts: 3,019
    edited 2008-11-28 10:06
    Hi kenmac, it depends on your array size.

    if it's a nice power of two size, say 8x8 bytes for example
    'getentry Yoffset, Xoffset   gets    arrayptr[noparse][[/noparse]y][noparse][[/noparse]x] for an ANYx32 array
    getentry
      mov ptr,Yoffset
      shl ptr,#5 ' shl ptr,#5 is same as ptr:=ptr*32
      add ptr,Xoffset
      add ptr,arrayptr
      rdbyte value,ptr
    getentry_ret
      ret
    ptr long 0
    arrayptr long somewhereinhubram
    value long 0
    
    



    or if it's an easily obtainable size, ie not too many bits to make the value to multiply the Y by, eg 40
    'getentry Yoffset, Xoffset   gets    arrayptr[noparse][[/noparse]y][noparse][[/noparse]x] for an ANYx40 array
    getentry
      mov ptr,Yoffset
      shl ptr,#2           ' = Yoffset*4
      add ptr,Yoffset    ' = Yoffset*5
      shl ptr,#3           ' = Yoffset*5*8 = *40
      add ptr,Xoffset
      add ptr,arrayptr
      rdbyte value,ptr
    getentry_ret
      ret
    ptr long 0
    arrayptr long somewhereinhubram
    value long 0
    
    



    if it's a nice power of two size, say 8x8 words for example
    'getentry Yoffset, Xoffset   gets    arrayptr[noparse][[/noparse]y][noparse][[/noparse]x] for an ANYx32 array
    getentry
      mov ptr,Yoffset
      shl ptr,#5 ' shl ptr,#5 is same as ptr:=ptr*32
      add ptr,Xoffset
      shl ptr,#1 ' shl ptr,#1 multiplies ptr by two for words
      add ptr,arrayptr
      rdword value,ptr
    getentry_ret
      ret
    ptr long 0
    arrayptr long somewhereinhubram
    value long 0
    
    



    or if it's an easily obtainable size, ie not too many bits to make the value to multiply the Y by, eg 40
    'getentry Yoffset, Xoffset   gets    arrayptr[noparse][[/noparse]y][noparse][[/noparse]x] for an ANYx40 array
    getentry
      mov ptr,Yoffset
      shl ptr,#2           ' = Yoffset*4
      add ptr,Yoffset    ' = Yoffset*5
      shl ptr,#3           ' = Yoffset*5*8 = *40
      add ptr,Xoffset
      shl ptr,#1 ' shl ptr,#1 multiplies ptr by two for words
      add ptr,arrayptr
      rdword value,ptr
    getentry_ret
      ret
    ptr long 0
    arrayptr long somewhereinhubram
    value long 0
    
    



    otherwise you'll have to use a multiply
    'getentry Yoffset, Xoffset   gets    arrayptr[noparse][[/noparse]y][noparse][[/noparse]x] for an ANYxANY array ( ANYx175 in this example )
    getentry
      mov multiplyA,Yoffset
      mov multiplyB,arraywidth
      call #multiplyAandB
      mov ptr,multiplyAnswer
      add ptr,Xoffset
      add ptr,arrayptr
      rdword value,ptr
    getentry_ret
      ret
    ptr long 0
    arrayptr long somewhereinhubram
    arraywidth long 175
    value long 0
    
    



    also, I've not put any boundary check in there, to keep the entries from getting data outside the array etc. but I'm sure you could add that yourself.

    and for storing change rdbyte to wrbyte, etc. obviously copied into another routine so you don't change reading to storing [noparse]:D[/noparse]

    hope this helps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
Sign In or Register to comment.