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 [2016-02-04 20:48] – [DCP/ISC] bitbreakerbase:advanced_optimizing [2017-11-20 08:49] – [SHX/SHY] bitbreaker
Line 932: Line 932:
 ===== SHX/SHY ===== ===== SHX/SHY =====
  
-When storing to zeropage you can also store the y- and x-register with an index in a fast and comfortable way. But often you will need the zeropage for other things. Sadly the instruction set of the 6510 is not orthogonal and thus this features are not available for 16 bit addresses. You can however workaround that nuisance by using SHX or SHY, but have to cope with the H component in it, as the stored values are anded with the highbyte of the destination address + 1. So most of the time you might want to store to $fexx to not run into any problems. In case you have to apply an additional static mask, or if you just need certain bits of teh stored values, you can of course choose a different address.+When storing to zeropage you can also store the y- and x-register with an index in a fast and comfortable way. But often you will need the zeropage for other things. Sadly the instruction set of the 6510 is not orthogonal and thus this features are not available for 16 bit addresses. You can however workaround that nuisance by using SHX or SHY, but have to cope with the H component in it, as the stored values are anded with the highbyte of the destination address + 1. So most of the time you might want to store to $fexx to not run into any problems. In case you have to apply an additional static mask, or if you just need certain bits of the stored values, you can of course choose a different address. If you start crossing a page with the index, the behaviour of this opcode changes radically. In those cases the Y-value becomes the highbyte of the address the values is stored at
  
 Want some example? Want some example?
Line 1154: Line 1154:
 Another good use can be made if you want to do a inc/dec ($xx),y what is actually not available. So here isc/dcp ($xx),y will help you out, as it is also available for the indirect y adressing mode.  Another good use can be made if you want to do a inc/dec ($xx),y what is actually not available. So here isc/dcp ($xx),y will help you out, as it is also available for the indirect y adressing mode. 
  
 +f.e.:
 +
 +<code>
 +ldy #..
 +lda (zp),y
 +clc
 +adc #..
 +sta (zp),y
 +bcc +
 +iny
 +isc (zp),y
 ++
 +</code>
 +
 +or
 +
 +<code>
 +ldy #..
 +lda (zp),y
 +sec
 +sbc #..
 +sta (zp),y
 +bcs +
 +iny
 +dcp (zp),y
 ++
 +</code>
 For decrementing a 16 bit pointer it is also of good use: For decrementing a 16 bit pointer it is also of good use:
  
Line 1345: Line 1372:
 So always try to form the term into something new and see if it performs better this way. So just remember the simple mathematic laws. So always try to form the term into something new and see if it performs better this way. So just remember the simple mathematic laws.
  
 +Now also think of that classical negation term:
 +
 +<code>
 +          lda num
 +          eor #$ff
 +          clc
 +          adc #$01
 +          sta neg
 +</code>
 +
 +Depending on what you have in register A, you can express it in many differnet ways:
 +
 +<code>
 +          ;a = $ff; carry set
 +          eor num
 +          adc #$00
 +          sta neg
 +          
 +          ;a = $00; carry set;
 +          sbc num
 +          sta neg
 +          
 +          ;a = $ff; carry clear
 +          adc num
 +          eor #$ff
 +          sta neg
 +          
 +          ;a = $00; carry clear;
 +          adc #$01
 +          sbc num
 +          sta neg
 +</code>
 +
 +There are of course also other expressions possible, just ponder a while about the term.
 ====== Running out of registers ====== ====== Running out of registers ======
  
base/advanced_optimizing.txt · Last modified: 2024-03-03 11:06 by bitbreaker