Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > ROL'in a byte onto itself
2016-03-01 17:04
mhindsbo
Account closed

Registered: Dec 2014
Posts: 50
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....
 
2016-03-02 12:16
mhindsbo
Account closed

Registered: Dec 2014
Posts: 50
i like Hoogo's for both its speed and size and Groepaz if you have the mem and need the long patterns. this was good input. thanks all.
2016-03-02 14:58
JackAsser

Registered: Jun 2002
Posts: 1989
Quote:
asl pattern
bcc no_action
inc pattern


This is excellent. I never thought of it.

1) Smaller
2) Faster
3) Doesn't clobber any registers except Status.

=> Perfect optimization. 10/10 rating.
2016-03-03 06:13
Oswald

Registered: Apr 2002
Posts: 5017
yup. +1
2016-03-03 09:49
Frantic

Registered: Mar 2003
Posts: 1627
Yes, very nice.

@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?

(A possible modification of this might be to use 0 as "take action flag" instead of 1, so that the inc is only performed when no particular action is to be taken, which might smoothen the averate cpu cycle consumtion each time the code is executed — including the execution of the code for the "action".)
2016-03-03 13:14
Oswald

Registered: Apr 2002
Posts: 5017
btw never thought of this, but RMW instructions work so, that the 6510 reads the byte into an 'inner' alu, so it can leave A alone ?
2016-03-03 13:25
JackAsser

Registered: Jun 2002
Posts: 1989
Quote: btw never thought of this, but RMW instructions work so, that the 6510 reads the byte into an 'inner' alu, so it can leave A alone ?

Not quite. There is not a single ALU, there are increment unit, shift units etc. Each unit can be used by different sources. Check http://vignette1.wikia.nocookie.net/microchip/images/c/c9/MOS-6.. for more in-depth.
2016-03-03 14:01
Bitbreaker

Registered: Oct 2002
Posts: 500
For a more readable version try this :-)
http://vignette1.wikia.nocookie.net/microchip/images/c/c9/MOS-6..

or:

http://www.weihenstephan.org/~michaste/pagetable/6502/6502.jpg
2016-03-03 14:49
Oswald

Registered: Apr 2002
Posts: 5017
Quote: Not quite. There is not a single ALU, there are increment unit, shift units etc. Each unit can be used by different sources. Check http://vignette1.wikia.nocookie.net/microchip/images/c/c9/MOS-6.. for more in-depth.



;)
2016-03-03 19:32
Hoogo

Registered: Jun 2002
Posts: 102
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...
2016-03-03 20:04
Frantic

Registered: Mar 2003
Posts: 1627
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.)
Previous - 1 | 2 | 3 | 4 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Guests online: 76
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Bromance  (9.6)
10 Memento Mori  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Webmasters
1 Slaygon  (9.7)
2 Perff  (9.6)
3 Morpheus  (9.5)
4 Sabbi  (9.5)
5 CreaMD  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.051 sec.