| |
mhindsbo
Registered: Dec 2014 Posts: 51 |
ROL'in a byte onto itself
What is the fastest and/or shortest code for rolling a pattern through a byte? I use it to trigger an action following a certain pattern. I came up with (18 cycles worst case / 12 bytes):
clc
lda pattern
bpl no_carry
sec
no_carry rol pattern
bcs take_action
if your pattern ends on a 1 (bit 0 = 1) then you could also do (17 cycles worst case / 13 bytes)
lda pattern
bne @cont
lda #%00110101 ; restore pattern
@cont asl
sta pattern
bcs take_action
any other variations? |
|
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
ldx pattern
lda table,x
sta pattern
|
| |
mhindsbo
Registered: Dec 2014 Posts: 51 |
Like it. 15 cycles (once you add the branch to take action) and 19 bytes (incl. branch and 8 byte table) if I am correct. If you have different patterns then full page table. |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
Should be able to replace the first version with this?
lda pattern
asl a
rol pattern
bcs take_action
|
| |
mhindsbo
Registered: Dec 2014 Posts: 51 |
indeed ... now why did I miss that ;-) |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
my 2 cents:
cmp #$80 will put highest bit into carry aswell. useful if you dont want to destroy a. |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Quote: my 2 cents:
cmp #$80 will put highest bit into carry aswell. useful if you dont want to destroy a.
Was just about to write it!! |
| |
Hoogo
Registered: Jun 2002 Posts: 105 |
asl pattern
bcc no_action
inc pattern |
| |
Peiselulli
Registered: Oct 2006 Posts: 81 |
asl
adc #$00 |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
Hoogo wins \O/ |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
I do like that (with a change of how the state is encoded) Groepaz' solution gives you arbitrary length sequences (as long as there are no more than 128 ones and no more than 128 zeros).
The table is contiguous, tooa fact that eluded me before I realised you could use a run of numbers ending with 127 for the zero states, and from 128 up for the ones (eg. use 128,125,126,129,127 to represent the sequence 10010) |
... 22 posts hidden. Click here to view all posts.... |
Previous - 1 | 2 | 3 | 4 - Next |