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 [2017-04-05 14:23] – [SHX/SHY] bitbreakerbase:advanced_optimizing [2018-09-13 14:26] – [Counting bits] bitbreaker
Line 321: Line 321:
 Further advantage of this method is, that we have an additional register free, as it is not used for an index anymore. But be aware! You have to take into account, that you have to store values top-down, as the stack-pointer decreases on every push. The advantage is, that if an interrupt occurs in between, it will not trash your values on the stack, as it pushes its 3 bytes (PC + Status) below your current position. All you need to take care of is, that you don't under-run the stack in case of an interrupt (needs 3 bytes, if you do a JSR in the interrupt-handler, another 2 bytes are needed per level), or trash still valid content in the upper part of the stack. Further advantage of this method is, that we have an additional register free, as it is not used for an index anymore. But be aware! You have to take into account, that you have to store values top-down, as the stack-pointer decreases on every push. The advantage is, that if an interrupt occurs in between, it will not trash your values on the stack, as it pushes its 3 bytes (PC + Status) below your current position. All you need to take care of is, that you don't under-run the stack in case of an interrupt (needs 3 bytes, if you do a JSR in the interrupt-handler, another 2 bytes are needed per level), or trash still valid content in the upper part of the stack.
 For reading out your values from stack you can either use pla but much easier via e.g. lda $0100,x For reading out your values from stack you can either use pla but much easier via e.g. lda $0100,x
 +
 +===== Counting with steps greater than 1 =====
 +
 +Later we will discover to do that also by SBX, but there's also another option to do that easily and being able to use LAX features for the index or even function that we walk along
 +
 +<code>
 +count = $20
 +           ldx #$00
 +           ldy #$00
 +-
 +           stx count,y
 +           iny
 +           txa
 +           sbx #-3
 +           cpx #$60
 +           bne -
 +
 +           ...
 +
 +.index     lax count
 +           ...
 +           do stuff with X and A
 +           ...
 +           inc .index + 1
 +</code>
 +
 +As you see the inc .index + 1 will fetch the value from the next location in zeropage on the next turn Thus we have A and X increased by 3 on each round, all done in 9 cycles, and with the option of destroying x later on.
  
 ===== Counting bits ===== ===== Counting bits =====
Line 932: Line 959:
 ===== 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 the stored values, you can of course choose a different address. Also, if you can life with an index starting from 1constructions like shy $feff,x (x = 1) are possibleThus values will still be anded with $ff but stored to $ffxx.+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 radicallyIn those cases the Y-value becomes the highbyte of the address the values is stored at
  
 Want some example? Want some example?
base/advanced_optimizing.txt · Last modified: 2024-03-03 11:06 by bitbreaker