Shop OBEX P1 Docs P2 Docs Learn Events
Linked list in pasm — Parallax Forums

Linked list in pasm

Ray0665Ray0665 Posts: 231
edited 2013-07-12 21:13 in Propeller 1
I am having difficulty with a linked list in PASM


The pasm routine is started from spin as follows
P1 := @L1
cognew(@begin,@P1)


In the PASM I fetch the starting address like this
DAT
ORG 0
Begin mov Ptr,par
rdlong NextPtr,Ptr ' Save the link
add Ptr,#4 ' Point to the data
<<< do stuff with data >>>>


and now I want to advance to the next element so I do this
mov Ptr,NextPtr


But it does not work where am I going wrong?


the list is defined like this, at the end of the DAT block


L1 long @L2, <data>
L2 long @L3, <data>
L3 Long @L1, <data>

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-12 14:46
    Addresses stored in a DAT section using the @ operator are actually object offsets, and not absolute addresses. The top object starts at address 16. You need to add 16 to the object offsets as follows:
    L1 long @L2+16, <data>
    L2 long @L3+16, <data>
    L3 long @L1+16, <data>
    
    If this is not in the top object you will need to add the object starting address to each address value at runtime.
  • Ray0665Ray0665 Posts: 231
    edited 2013-07-12 14:52
    Got it, Now is there a way to capture the starting offset symbolically
    for example could I define the links like this
    L1 long @L2+begin,<data> where begin is the first label
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-12 15:13
    I don't know of any way to get the starting address within a DAT section with the Spin tool. If you use BST instead of the Spin tool you can use the @@@ operator to get absolute addresses. However, you're code will not compile under the Spin tool if you do this. With BST, your code would look like this:
    L1 long @@@L2, <data>
    L2 long @@@L3, <data>
    L3 long @@@L1, <data>
    
  • msrobotsmsrobots Posts: 3,709
    edited 2013-07-12 21:13
    You could work with offsets instead of addresses
    DAT
    ORG 0
    Begin mov Ptr,par
             mov FirstPtr,par ' keep Address of First element
    
             rdlong NextPtr,Ptr ' Save the offset of link 
             add NextPtr,FirstPtr    ' add Address of first element to get Hubaddress in NextPtr
    
             add Ptr,#4 ' Point to the data
    do whatever
    

    having your List with offsets instead of Addresses

    L1 long @L2-@L1, <data>
    L2 long @L3-@L1, <data>
    L3 Long @L1-@L1, <data>

    Enjoy!

    Mike
Sign In or Register to comment.