Shop OBEX P1 Docs P2 Docs Learn Events
A little PASM help, please! — Parallax Forums

A little PASM help, please!

markaericmarkaeric Posts: 282
edited 2010-08-27 11:13 in Propeller 1
Alas, my first foray into PASM. My only previous encounter with ASM was a little bit on the SX, and that's pretty much all forgotten (except for having to move vars to the working register).

Anyways, I know this is real simple, so don't laugh at me too hard!

What I'm trying to do is write data to an array in cog ram. How do I go about addressing each long? Do I simply add some sort of label at the beginning of the array, and then do something like:

add LabelName, 1
mov LabelName, Data

or do I have to create another variable which I use to point to the array? If so, how do I go about doing that? I've been searching for the answer, but didn't come across it. If I did, then I certainly didn't recognize it. I did see an example in Phil Pilgrim's tricks and traps, but there seemed to be some additional complexities that I was confused about.

Thanks,
Mark

Comments

  • HarleyHarley Posts: 997
    edited 2010-08-26 19:28
    In your VARs, you need to set up an array

    VAR array(value of length of array)

    Now Spin can access this array if needed. When you do 'cognew' use the array label as 2nd expression. Then in PASM, PAR provides you access to this array. You need RDLONG or WRLONG to read from/write to the array. Increment pointer to PAR by 4 for each location. Note, WRLONG uses 'value' in the destination and pointer in the source; a bit bass-ackward.

    At least this is the way I understand and have used arrays. I've used a 300+ array for an A/D, with the first two locations reserved to pass variables between Spin and PASM.

    Don't fall into the trap of accidently assigning less locations to the array than PASM uses. That cog trampled over the variables following 'array' making for a mess to debug
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-08-26 20:16
    You are referring to an array in Cog Ram.

    mov ArrayPtr, #Array 'setup the pointer to the first array data address
    .....
    loop xxx xxxx, ArrayPtr 'do something with the array long
    add ArrayPtr, #1 'point to next array long
    jmp #loop



    ArrayPtr long 0
    Array long 0
    long 0
    long 0
  • markaericmarkaeric Posts: 282
    edited 2010-08-26 20:26
    Cluso99 wrote: »
    You are referring to an array in Cog Ram.

    mov ArrayPtr, #Array 'setup the pointer to the first array data address
    .....
    loop xxx xxxx, ArrayPtr 'do something with the array long
    add ArrayPtr, #1 'point to next array long
    jmp #loop



    ArrayPtr long 0
    Array long 0
    long 0
    long 0


    Makes perfect sense! Thanks!
  • kuronekokuroneko Posts: 3,623
    edited 2010-08-26 20:28
    markaeric wrote: »
    Makes perfect sense! Thanks!

    It does? Cog array access without indirection?
  • markaericmarkaeric Posts: 282
    edited 2010-08-26 23:53
    Nope.. Nevermind.. I don't get it.

    I'm messing a bit with movd now. Not sure if it even works yet. Is there a different way?

    Edit: Doh! Now I found this thread: http://forums.parallax.com/showthread.php?t=118875
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-08-27 00:56
    With movd, movs and movi don't forget that it takes an instruction in between due to pipelining in the prop.
  • ericballericball Posts: 774
    edited 2010-08-27 08:17
    To access an array in HUB RAM:
    ' data = BASE[INDEX]
    	MOV	ptr, INDEX
    	SHL	ptr, #2		' 1 for WORD, 2 for LONG, not required for byte
    	ADD	ptr, BASE
    	RDLONG	data, ptr
    
    ' data = BASE[i++]
    	MOV	ptr, BASE
    	RDLONG	data, ptr
    	ADD	ptr, #4		' 1 for BYTE, 2 for WORD, 4 for LONG
    

    If the array is in COG RAM then you use self modifying code:
    ' data = BASE[INDEX]
    	MOVS	S1, #BASE
    	ADD	S1, #INDEX
    	NOP			' required for pipeline
    S1	MOV	data, BASE+0
    
    ' data = BASE[i++]
    	MOVS	S1, #BASE
    S1	MOV	data, BASE+0
    	ADD	S1, #1		' may be placed before MOV data if desired
    
  • markaericmarkaeric Posts: 282
    edited 2010-08-27 11:13
    I do see now. I was a bit mislead due to compile-time addressing.
Sign In or Register to comment.