Cnt Rollover
James Newman
Posts: 133
There have been a few discussions on this, but I have a hard time finding what's decided. Also, it doesn't seem to be mentioned in the Tricks and Traps.
What's the best way to handle cnt rollover (in asm) when trying to check a delay.
I have 3 variables, ie: start, delay, and cnt.
Did we ever decide on the best way of checking if cnt > start+delay?
(Edit)
I did make a little table with the possible correct responses, btw.
1) Cnt < start < start+delay -> Delay time exceeded
2) Cnt < start+delay < start -> Still in Delay
3) start < start+delay < Cnt -> Delay time exceeded
4) start < Cnt < start+delay -> Still in Delay
5) start+delay < Cnt < start -> Delay time exceeded
6) start+delay < start < Cnt -> Still in Delay
In 3 and 4 no values have rolled over.
In 1, Cnt has rolled over
In 2, Cnt has rolled over, but is less than start+delay, which has also rolled over
In 5, Cnt has rolled over, and has passed start+delay, which has also rolled over
In 6, start+delay has rolled over, but Cnt has not yet.
Post Edited (James Newman) : 2/18/2008 5:14:15 AM GMT
What's the best way to handle cnt rollover (in asm) when trying to check a delay.
I have 3 variables, ie: start, delay, and cnt.
Did we ever decide on the best way of checking if cnt > start+delay?
(Edit)
I did make a little table with the possible correct responses, btw.
1) Cnt < start < start+delay -> Delay time exceeded
2) Cnt < start+delay < start -> Still in Delay
3) start < start+delay < Cnt -> Delay time exceeded
4) start < Cnt < start+delay -> Still in Delay
5) start+delay < Cnt < start -> Delay time exceeded
6) start+delay < start < Cnt -> Still in Delay
In 3 and 4 no values have rolled over.
In 1, Cnt has rolled over
In 2, Cnt has rolled over, but is less than start+delay, which has also rolled over
In 5, Cnt has rolled over, and has passed start+delay, which has also rolled over
In 6, start+delay has rolled over, but Cnt has not yet.
Post Edited (James Newman) : 2/18/2008 5:14:15 AM GMT
Comments
I'm sure you will therefore update that thread when you have got this working in your own project
There's also the Propeller Wiki where people are welcome to share their knowledge and experiences - propeller.wikispaces.com
(b) As Hippy says.
(c) There is no difference between signed or unsigned ADD and SUB other than wrt their flag setting, which however is more complex than you might think in the beginning...
(d) It is exactly as Mike said, but the kind of SUB does not matter. However in PASM you have ALWAYS to decide whether signed or unsigned CMP is appropriate, although unsigned CMP is needed more often...
Post Edited (deSilva) : 2/18/2008 10:05:18 PM GMT
I think it should be listed in the tricks/traps, atleast as a sort of reminder to newbies that cnt does infact rollover, and what effect that will have on any code.
Thanks all, even though this wasn't my problem -really- it did lead me to my problem... which I should have seen.