| |
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? |
|
... 22 posts hidden. Click here to view all posts.... |
| |
Hoogo
Registered: Jun 2002 Posts: 105 |
Quoting Frantic@Hoogo: I'd like to add this to codebase, but before doing so I just want to ask if you would rather prefer to do it yourself? Don't bother, just add it. I'm a little surprised by all this reaction... |
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
Quote: Quoting Frantic@Hoogo: I'd like to add this to codebase, but before doing so I just want to ask if you would rather prefer to do it yourself? Don't bother, just add it. I'm a little surprised by all this reaction...
I guess nerdy coders like us find the simplicity of such small and simple tricks beautiful.
https://codebase64.org/doku.php?id=base:rotate_byte_and_act_on_..
(Couldn't come up with a sensible name for the article really, but hopefully it is comprehensible.) |
| |
Digger
Registered: Mar 2005 Posts: 437 |
What's could be a practical application for that? |
| |
mhindsbo
Registered: Dec 2014 Posts: 51 |
I use it for an alternating fire pattern. This piece of code sits in the fire function and decides if it fires or not when called |
| |
Copyfault
Registered: Dec 2001 Posts: 478 |
Quoting Hoogoasl pattern
bcc no_action
inc pattern
Wow, that's true art!
Thanks for being (or better getting) active again, Frank ;) |
| |
Style
Registered: Jun 2004 Posts: 498 |
Quote: Quoting Hoogoasl pattern
bcc no_action
inc pattern
Wow, that's true art!
Thanks for being (or better getting) active again, Frank ;)
Id use
ASL mem
ADC #0 |
| |
Hoogo
Registered: Jun 2002 Posts: 105 |
Quoting StyleASL mem
ADC #0 It's easier, faster and shorter, but does not work :) Where's the Accu coming from, and where does it go? |
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
Quote:It's easier, faster and shorter, but does not work
AEG would love it *g* |
| |
Style
Registered: Jun 2004 Posts: 498 |
Quote: Quoting StyleASL mem
ADC #0 It's easier, faster and shorter, but does not work :) Where's the Accu coming from, and where does it go?
Oh was that a prerequisite? :)
LDA groep
ASL
ADC #0
STA groep
There ;)
(wanders off to find copy of "coding drunk for beginners") |
| |
mhindsbo
Registered: Dec 2014 Posts: 51 |
Yes the requirement was code that works (checking chapter 1 in "coding drunk for beginners" ;-) just need to add the branch to take action ;-)
All in all Hoogo's solution is both shortest and fastest. Part of the joy I get from coding on the C64 are finding elegant short, fast and clean solutions, within the constraints of the system, and I really like the aesthetics of this one :-) |
Previous - 1 | 2 | 3 | 4 - Next |