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-11-20 08:49] – [SHX/SHY] bitbreaker | base:advanced_optimizing [2021-04-19 08:26] – [LAX] 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 874: | Line 901: | ||
Actually you can use LAX also with an immediate value, but it behaves a bit unstable regarding the given immediate value. However when simply doing an LAX #$00 you are fine. | Actually you can use LAX also with an immediate value, but it behaves a bit unstable regarding the given immediate value. However when simply doing an LAX #$00 you are fine. | ||
+ | |||
+ | lda $xxxx,y is not available as 8 bit version, so an lda $xx,y is not possible. With lax $xx,y there is howeever a way to imitate a lda $xx,y at the cost of destroying x. | ||
===== SAX/SHA ===== | ===== SAX/SHA ===== | ||
Line 1403: | Line 1432: | ||
sbc num | sbc num | ||
sta neg | sta neg | ||
+ | | ||
+ | ;num in a, carry set | ||
+ | lda num | ||
+ | sbc #$01 | ||
+ | eor #$ff | ||
</ | </ | ||
- | There are of course also other expressions possible, just ponder a while about the term. | + | 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's about forming terms with logical operations? We notice, that for e.g. (a + b) xor $ff is the same as (a xor $ff) - b: | ||
+ | |||
+ | < | ||
+ | lda num1 | ||
+ | clc | ||
+ | adc num2 | ||
+ | eor #$ff | ||
+ | |||
+ | ;can also be written as | ||
+ | lda num1 | ||
+ | eor #$ff | ||
+ | sec | ||
+ | sbc num2 | ||
+ | </ | ||
====== Running out of registers ====== | ====== Running out of registers ====== | ||
base/advanced_optimizing.txt · Last modified: 2024-03-03 11:06 by bitbreaker