User Tools

Site Tools


base:advanced_optimizing

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
Next revisionBoth sides next revision
base:advanced_optimizing [2021-04-19 08:26] – [LAX] bitbreakerbase:advanced_optimizing [2022-02-08 13:56] – [Shifting] bitbreaker
Line 718: Line 718:
  
 The advantage is, that you can move bits also across registers and are not restricted to the accumulator only. The advantage is, that you can move bits also across registers and are not restricted to the accumulator only.
 +
 +When shifting, we handle 9 bits, as the bit falling out at one edge of the byte will be stored in the carry, and the carry will be shifted in. This will introduce a gap of one bit, when we wrap around bits:
 +
 +<code>
 +        lda #%11111111
 +        clc
 +        rol
 +        rol
 +        ;-> A = %11111101
 +        ;              ^
 +        ;             gap :-(
 +</code>
 +
 +To avoid that behaviour there's several ways around it:
 +
 +<code>
 +        lda #%11111111
 +        asl
 +        adc #0
 +        
 +        ...
 +        
 +        lda #%11111111
 +        anc #$ff
 +        rol
 +        
 +        ...
 +        
 +        lda #%11111111
 +        cmp #$80
 +        rol
 +</code>
 +
 +This way bit 7 is copied to carry first and then shifted in on the right end again.
 ====== Jumpcode ====== ====== Jumpcode ======
  
Line 1539: Line 1573:
  
 <code> <code>
-        lda bmp+        lda bmp       ;could also use lax bmp, sbx #$08, stx bmp to save more cycles
         sec         sec
         sbc #$08         sbc #$08
base/advanced_optimizing.txt · Last modified: 2024-03-03 11:06 by bitbreaker