djmips, on Sun Jun 12, 2005 6:09 PM, said:
LAX word INX AND #$F0 STA word TXA AND #$0F ORA word STA word
A late reply to the starting hack of this thread. If you got a free byte of memory space and you could initialise that before the loop this should be faster:
At an init stage store the top 4 bits in a variable:
lda word and #$f0 sta hi
And in your loop when you are iterating and need the wraparound increment on lower 4 bits:
ldx word ; 3 inx ; 2 txa ; 2 and #$0f ; 2 ora hi; 3 sta word ; 3
Uses a total of 15 cycles, 4 less than the one quoted assuming word and hi are in zero page.
Well, if you can assume that your "word" variable bit 4 is always zero (so counter starts from one of $00,$20,$40,$60,$80,$a0,$c0,$e0) you could do this also:
ldx word; 3 inx ; 2 txa ; 2 and #$ef; 2 sta word; 2
Which is only 11 cycles!
Edited by johncl, Mon Dec 29, 2008 7:46 AM.













