base:advanced_optimizing
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
base:advanced_optimizing [2017-11-20 08:49] – [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 ===== |
base/advanced_optimizing.txt · Last modified: 2024-03-03 11:06 by bitbreaker