ASM: Senior moments with CNT
Nick Mueller
Posts: 815
Hi!
It seems, I do have senior moments with doing some math with CNT. Or the problem is somewhere else.
I do have a variable (lets call it OnCNT) that is -if some conditions are true- loaded with CNT (plus some offset we can ignore for now). right after that, an other variable (called OffCNT) is set with OnCNT + some offset.
In a loop, the variables OnCNT and OffCnt are checked and compared to CNT. If the CNT has passed bejond (or equal) OnCNT, some action is taken. If CNT has passed bejond (or equal) OffCNT, some other action.
Snipplett:
Hopefully so far so good.
Now to the comparison:
What's wrong with that? Is it wrong? And where?
I'm aware, that CNT and OnCNT/OffCNT will wrap over. The distance between CNT and OnCNT/OffCNT can only be much less than 1 second, so that can't be the problem.
The code I had for prototyping in SPIN worked and looked like this:
Thanks!
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
It seems, I do have senior moments with doing some math with CNT. Or the problem is somewhere else.
I do have a variable (lets call it OnCNT) that is -if some conditions are true- loaded with CNT (plus some offset we can ignore for now). right after that, an other variable (called OffCNT) is set with OnCNT + some offset.
In a loop, the variables OnCNT and OffCnt are checked and compared to CNT. If the CNT has passed bejond (or equal) OnCNT, some action is taken. If CNT has passed bejond (or equal) OffCNT, some other action.
Snipplett:
mov :OnCNT, CNT mov :OffCNT, :OnCNT adds :OffCNT, #SomeValue
Hopefully so far so good.
Now to the comparison:
subs CNT, :OnCNT WZ, WC, WR if_b jmp #:doSomethingElse
What's wrong with that? Is it wrong? And where?
I'm aware, that CNT and OnCNT/OffCNT will wrap over. The distance between CNT and OnCNT/OffCNT can only be much less than 1 second, so that can't be the problem.
The code I had for prototyping in SPIN worked and looked like this:
OnCNT:= CNT OffCNT:= OnCNT + SomeValue ... if (CNT - OnCNT => 0) DoSomethingThatIsUsefull
Thanks!
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 12/4/2007 12:28:30 AM GMT
And the "WR" doesn't change that? I mean, it shouldn't try to write, I only need the flags. Do I?
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
but didn't make it better.
If someone can confirm that this code is right, I'll have to chase bugs somewhere else ...
EDIT:
I think that adding the offset with "ADDS :OffCNT, #SomeValue" is wrong. I need the wrap-around.
I wonder how it worked in SPIN.
I'll have a sleep, it's 2 o'clock in the morning.8-/
Thanks,
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
Post Edited (Nick Mueller) : 12/4/2007 1:18:32 AM GMT
CNT is "unsigned" - don't use SUBS until you understand the finer meaning of its carry SUB will do in all cases, followed by a CMP.
For "shadow registers": read my contributions... I think I explained it in detail (and many times...)