Shop OBEX P1 Docs P2 Docs Learn Events
First time using pointers, needs review — Parallax Forums

First time using pointers, needs review

Mag748Mag748 Posts: 266
edited 2013-04-08 08:46 in Propeller 1
Hello,

I just discovered using pointers in assembly for arrays. I modified an existing file that worked, to use arrays with pointers, and now it no longer works. I've been pouring over it all day to try and find any mistakes, but I though I would put it up here in case anyone out there has a second to look over what I'm doing and who might be able to catch any obvious mistakes.

Any thoughts would be greatly appreciated.

Thanks,
Marcus

MSGEQ7 Driver 4.5.13c.spin

Comments

  • tonyp12tonyp12 Posts: 1,951
    edited 2013-04-05 13:59
    Arrays uses selfmod code, it's hard to get a grip around that concept at first.
    Always have line of code before the 0-0 line comes up, here I use mov mycounter,#8 as to avoid a nop
            movs         arrayPt, #Arraydata        'fill in the blank 0-0 below
            mov          mycounter,#8  
    arrayPt mov          outa,0-0
            add          arrayPt,#1                 'next long
            djnz         mycounter,#arrayPt         'loop for 8 times
    
    Arraydata   long     $00A0FE00,$00B800AA,$0022FE00,$005500B1,$0102EE02,$0000202A,$0000AE02,$0200010A
    mycounter   res      1
    


    If the array is on the destination side.
            movd         arrayPt, #Arraydata        'fill in the blank 0-0 below
            mov          mycounter,#8  
    arrayPt mov          0-0,ina
            add          arrayPt, _bit9             'next long
            djnz         mycounter,#arrayPt         'loop for 8 times
    
    _bit9       long     |< 9 ' eg 512
    Arraydata   res      8
    mycounter   res      1
    
  • JonnyMacJonnyMac Posts: 9,108
    edited 2013-04-05 15:10
    I created a couple subroutines for my PASM programs that need to read from or write to a cog array. Perhaps they'll be of help.
    ' read element from PASM array
    ' -- pass table address in "tpntr"
    ' -- pass element index in "tidx"
    ' -- result returned in "tvalue"
    
    read                    mov     t1, tpntr
                            add     t1, tidx
                            movs    rdval, t1                       ' set source for mov
                            nop
    rdval                   mov     tvalue, 0-0
    read_ret                ret
    
    
    
    ' write element to PASM array
    ' -- pass table address in "tpntr"
    ' -- pass element index in "tidx"
    ' -- pass value to write in "tvalue"
    
    write                   mov     t1, tpntr
                            add     t1, tidx
                            movd    wrval, t1                       ' set destination for mov
                            nop
    wrval                   mov     0-0, tvalue
    write_ret               ret
    
  • kuronekokuroneko Posts: 3,623
    edited 2013-04-05 17:02
    mov _arrayPtr, @Array moves the hub address of ArrayA into _arrayPtr, NG. You really want the cog register location, i.e. mov _arrayPtr, #Array. Also, what's the idea behind shl t1, windowSize+2? In the code you posted windowSize+2 is the same as windowIdx. Can you elaborate?


    A relative to the current DAT block
  • Mag748Mag748 Posts: 266
    edited 2013-04-08 08:46
    JonnyMac, tonyp12,

    Thank you both for the routine suggestions. I added that to my spin file and it helped my understand the process, and I will do this from now on.

    kuroneko,

    Great catch on the @ vs. # mistake I made. that helped. And regarding the +2 on the shl command, I was thinking I needed to shift all my offsets and array indices left by 2 since a long is 4 bytes in Spin, BUT I didn't realize that all commands are acting on LONGs in ASM, so I got rid of all those extra left shifts by 2 and everything works like a charm!

    Thanks for all your help :)
Sign In or Register to comment.