First time using pointers, needs review
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
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
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 1If 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' 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 retA relative to the current DAT block
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