base:advanced_optimizing
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
base:advanced_optimizing [2017-04-05 14:23] – [SHX/SHY] bitbreaker | base: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, | 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, | ||
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' | ||
+ | |||
+ | < | ||
+ | count = $20 | ||
+ | ldx #$00 | ||
+ | ldy #$00 | ||
+ | - | ||
+ | stx count,y | ||
+ | iny | ||
+ | txa | ||
+ | sbx #-3 | ||
+ | cpx #$60 | ||
+ | bne - | ||
+ | |||
+ | ... | ||
+ | |||
+ | .index | ||
+ | ... | ||
+ | do stuff with X and A | ||
+ | ... | ||
+ | inc .index + 1 | ||
+ | </ | ||
+ | |||
+ | 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. | + | 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. |
Want some example? | Want some example? |
base/advanced_optimizing.txt · Last modified: 2024-03-03 11:06 by bitbreaker