??? 07/05/06 03:42 Modified: 07/05/06 03:48 Read: times |
#119637 - Vertically incrementing Responding to: ???'s previous message |
Suresh said:
I couldnt find how the two counters (ctrA, ctrB) are been used to achieve this. A standard 4 step counter using two bits of a byte "knows" the following states: 1. step: XXXX XX00 2. step: XXXX XX01 3. step: XXXX XX10 4. step: XXXX XX11 You can also do it this way: 1. step: X00X XXXX 2. step: X01X XXXX 3. step: X10X XXXX 4. step: X11X XXXX This is trivial, of course. As the two bits are within the same byte one could call it a "horizontal counter". I don't know whether this term exists. But it shall demonstrate here the difference to another type of counter, namely the "vertical counter". This one uses bits of different bytes, where the bits are at the same position within the byte. In the code example of Hans the two bits sit in the bytes CtrA and CtrB and the counting scheme looks as follows: 1. step: CtrB: XXXX XXX0 CtrA: XXXX XXX0 2. step: CtrB: XXXX XXX1 CtrA: XXXX XXX0 3. step: CtrB: XXXX XXX0 CtrA: XXXX XXX1 4. step: CtrB: XXXX XXX1 CtrA: XXXX XXX1 You can also do it this way: 1. step: CtrB: XXXX X0XX CtrA: XXXX X0XX 2. step: CtrB: XXXX X1XX CtrA: XXXX X0XX 3. step: CtrB: XXXX X0XX CtrA: XXXX X1XX 4. step: CtrB: XXXX X1XX CtrA: XXXX X1XX or this way: 1. step: CtrB: X0XX XXXX CtrA: X0XX XXXX 2. step: CtrB: X1XX XXXX CtrA: X0XX XXXX 3. step: CtrB: X0XX XXXX CtrA: X1XX XXXX 4. step: CtrB: X1XX XXXX CtrA: X1XX XXXX The interesting question is now: How to increment such a vertical counter? The answer is simple: Whenever the vertical counter is incremented (by one step) the bit in byte CtrB changes its state, means was it "0" becomes it "1" and was it "1" becomes it "0". This is done by the instruction: xrl CtrB,#0ffh You could also do it with the "CPL" instruction, but then the byte must sit in the accumulator. The bit in byte CtrA, on the other hand, becomes "1", when the bit in CtrA and the bit in CtrB were of different states. Otherwise it becomes "0". So, mov a,CtrB xrl CtrA,a does the trick! Hope this helps, Kai |