User Tools

Site Tools


playground:reversing_bits_in_a_byte

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
playground:reversing_bits_in_a_byte [2020-02-14 22:46] verzplayground:reversing_bits_in_a_byte [2020-03-12 13:05] (current) tlr
Line 21: Line 21:
  
 -- --
-this would be faster (enter with the value in .A, result in .A, .X will be 0)+this would be equally fast, at 100cycl +rts (enter with the value in .A, result in .A, .X will be 0)
 <code> <code>
         ldx #8         ldx #8
Line 31: Line 31:
  
         rts         rts
 +</code>
 +
 +or unrolled (56 cycl +rts):
 +<code>
 +        asl 
 +        ror $2
 +        asl 
 +        ror $2
 +        asl 
 +        ror $2
 +        asl 
 +        ror $2
 +        asl 
 +        ror $2
 +        asl 
 +        ror $2
 +        asl 
 +        ror $2
 +        asl 
 +        lda $2
 +        ror
 +        rts
 +</code>
 +
 +--
 +Optimized version, at 84cycl +rts (enter with the value in .A, result in .A)
 +<code>
 + sta $02 ; 3
 + lda #1 ; 2
 +lp:
 + ror $02 ; 5
 + rol ; 2
 + bcc lp ; 3(2)
 + ; =84
 + rts
 +</code>
 +
 +or slightly unrolled:
 +<code>
 + sta $02 ; 3
 + lda #1 ; 2
 +lp:
 + ror $02 ; 5
 + rol ; 2
 + ror $02 ; 5
 + rol ; 2
 + bcc lp ; 3(2)
 + ; =72
 + rts
 </code> </code>
  
playground/reversing_bits_in_a_byte.1581716765.txt.gz · Last modified: 2020-02-14 22:46 by verz