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
base:advanced_optimizing [2022-12-09 14:47] – [Shifting] bitbreakerbase:advanced_optimizing [2024-03-03 11:06] (current) – [ASR] bitbreaker
Line 907: Line 907:
                  
 In the same way this method can also be used to set bits (for e.g. with adc #$81) or to toggle bits. In the same way this method can also be used to set bits (for e.g. with adc #$81) or to toggle bits.
 +
 +When masking out bits, SAX or SBX is often a good choice.
 + 
 +<code>
 +       lax value
 +       and #%11110000
 +       sta highnibble
 +</code>
 +
 +After this we need to restore from X to mask the lower bits, better then another lda value, but still. 
 +
 +<code>      
 +       lda value
 +       ldx #%11110000
 +       sax highnibble
 +</code>
 +
 +This looks already better, we have the original value still in A and can do another mask operation.
 +
 +<code>
 +       lax value
 +       eor #%000011111
 +       sax highnibble       
 +</code>
 +
 +This looks even better, we can reuse X here and also A still contains the original bits, but in an inverted manner. So this opens up more options of reusing the original value at more than one register which gives potential for further savings.
 +This was spotted in Krill's loader when doing lookups on the GCR tables, so thanks to Krill here :-)
 ====== Illegal opcodes ====== ====== Illegal opcodes ======
  
Line 1031: Line 1058:
  
 <code> <code>
-        and #$ff+        and #$fe
         lsr         lsr
-        clc 
 </code> </code>
 ===== ARR ===== ===== ARR =====
Line 1459: Line 1485:
 </code> </code>
  
-Depending on what you have in register A, you can express it in many differnet ways:+Depending on what you have in register A, you can express it in many different ways:
  
 <code> <code>
Line 1489: Line 1515:
 There are of course also other expressions possible, just ponder a while about the term. Also the carry flag after the negation can be influenced, depending on using sbc or adc for most cases ($00/$ff will cause an overflow). There are of course also other expressions possible, just ponder a while about the term. Also the carry flag after the negation can be influenced, depending on using sbc or adc for most cases ($00/$ff will cause an overflow).
  
-How'about forming terms with logical operations? We notice, that for e.g. (a + b) xor $ff is the same as (a xor $ff) - b:+How about forming terms with logical operations? We notice, that for e.g. (a + b) xor $ff is the same as (a xor $ff) - b:
  
 <code> <code>
base/advanced_optimizing.1670593650.txt.gz · Last modified: 2022-12-09 14:47 by bitbreaker