problem w/ mov :x,cnt
janb
Posts: 74
·Hi,
I spent already few days to debug this problem, wrote from scratch special test code and
at the end decided to ask for help. There is sth fundamentally wrong w/ my assembler code.
The grand scheme looks as follows:
cog0 runs SPIN code + TV driver. It owns 3 arrays & 1 semaphore-like variable 'myStat'
cog0 passes iBuf[noparse]/noparse to ASM code running on cog1
The goal· of cog1 is to wait until myStat==1, then fill internal cog1 array with some series of values and export it back to the Hub array to the address dataAr[noparse]/noparse.
Next cog0· does some QA on the dataAr[noparse]/noparse, clears it, resets myStat to 1 and all repeats.
This scheme works very good under one condition:
I can't use
in the assembler loop filling internal cog1 array. The code of this ASM function is below. Full code is attached - (hook up TV to pins 12,..., LED on pin16 will show the ASM code is working)
If I choose to fill ASM array with values incremented by 20 all works (as in the example above), even for 1000 events (cycles of calling ASM code)
But if I simply· swap 2 active lines·to
·propeller· becomes unstable.
It always runs in to some trouble after _many_ events:
- most often it works fine for 50-80 events and suddenly the values in output array seen by cog0 are wrong (increment between values is not 20 - I abort cog0 in such case)
- sometimes ASM code stays forever in the FillCogArray procedure - I see it because myStat seen by cog0 is 2 and LED on pin 16 still blinks
- sometimes TV display disappears - meaning sth wrong happens to pins12,....
- never the same problem will happen twice in the row
The bottom line is ASM code gets sick if I try to access very often clock counter .
Has any one seen problem like this?
Is there sth obviously wrong in my code?
Hope it is sth trivial
Jan··
Post Edited (janb) : 9/11/2007 3:15:16 AM GMT
I spent already few days to debug this problem, wrote from scratch special test code and
at the end decided to ask for help. There is sth fundamentally wrong w/ my assembler code.
The grand scheme looks as follows:
cog0 runs SPIN code + TV driver. It owns 3 arrays & 1 semaphore-like variable 'myStat'
long iBuf[noparse][[/noparse]iBLen] ' ASM input buf long oBuf[noparse][[/noparse]oBLen] ' ASM output buf long dataAr[noparse][[/noparse]arLen] ' I/O data array long myStat 'status of control, LOCK-protected
cog0 passes iBuf[noparse]/noparse to ASM code running on cog1
The goal· of cog1 is to wait until myStat==1, then fill internal cog1 array with some series of values and export it back to the Hub array to the address dataAr[noparse]/noparse.
Next cog0· does some QA on the dataAr[noparse]/noparse, clears it, resets myStat to 1 and all repeats.
This scheme works very good under one condition:
I can't use
mov :bhla, cnt
in the assembler loop filling internal cog1 array. The code of this ASM function is below. Full code is attached - (hook up TV to pins 12,..., LED on pin16 will show the ASM code is working)
FillCogArray { in COG } mov :val,#20 movd :self, #cogArr 'set initial address mov :i, #cogArrLen ' set size of array :self mov 0-0, :val 'store some default value add :self, :d_inc 'incr destination in instruction above 'mov :val,cnt 'BREAKS ~1/1000 add :val,#20 'WORKS always nop djnz :i, #:self 'go to next element :i long 0 :val long 0
:d_inc LONG $0000_0200 FillCogArray_ret ret
If I choose to fill ASM array with values incremented by 20 all works (as in the example above), even for 1000 events (cycles of calling ASM code)
But if I simply· swap 2 active lines·to
mov :val,cnt 'BREAKS ~1/1000 'add :val,#20 'WORKS always
·propeller· becomes unstable.
It always runs in to some trouble after _many_ events:
- most often it works fine for 50-80 events and suddenly the values in output array seen by cog0 are wrong (increment between values is not 20 - I abort cog0 in such case)
- sometimes ASM code stays forever in the FillCogArray procedure - I see it because myStat seen by cog0 is 2 and LED on pin 16 still blinks
- sometimes TV display disappears - meaning sth wrong happens to pins12,....
- never the same problem will happen twice in the row
The bottom line is ASM code gets sick if I try to access very often clock counter .
Has any one seen problem like this?
Is there sth obviously wrong in my code?
Hope it is sth trivial
Jan··
Post Edited (janb) : 9/11/2007 3:15:16 AM GMT
Comments
So you have to skip the fancy ":" stuff and use "global" names... no other chance...
Or you "jump over" the variables...
that was it. If I think back how many hours I have invested to isolate this problem!
Thank you very much for this 2 lines of deep insight.
I wish this warning would be part of the Parallax official writeup in the Assembler section.
Jan