06-24-2003, 09:28 AM
Yes nathan, it may count if I can figure out what you mean by a "cycling counter". Does your one instruction finish the whole idea?
*****
EDIT:
I just figured out with pencil and paper what you want to do. It's brilliant!
You want to do (or cycle) some code max number of times, where max is a power of 2. Actually, because of the logic, you need to do this from zero to max-1.
You need the following setup or initialization.
max = (some power of 2) - 1
counter = 0
gosub logic
Then, your one line algorittm embedded in a loop becomes:
loop:
counter = (counter + 1) and max
gosub logic
goto loop
In this manner, your one line instruction to increment and reset will enable us to perform the subroutine called "logic" repeatedly for values of zero to max.
The rest of you should notice the subtle point of his instruction, in that when the counter is incremented 1 beyond max, the "and" wraps it around to zero.
*****
*****
EDIT:
I just figured out with pencil and paper what you want to do. It's brilliant!
You want to do (or cycle) some code max number of times, where max is a power of 2. Actually, because of the logic, you need to do this from zero to max-1.
You need the following setup or initialization.
max = (some power of 2) - 1
counter = 0
gosub logic
Then, your one line algorittm embedded in a loop becomes:
loop:
counter = (counter + 1) and max
gosub logic
goto loop
In this manner, your one line instruction to increment and reset will enable us to perform the subroutine called "logic" repeatedly for values of zero to max.
The rest of you should notice the subtle point of his instruction, in that when the counter is incremented 1 beyond max, the "and" wraps it around to zero.
*****