Skip to content

Comments

Fix issue w/ A values used after LDA #$00 / sta $address -> STZ $address optimization. #11

Merged
CTalkobt merged 1 commit intomainfrom
feature/65c02_stz_a_usage
Jan 6, 2026
Merged

Fix issue w/ A values used after LDA #$00 / sta $address -> STZ $address optimization. #11
CTalkobt merged 1 commit intomainfrom
feature/65c02_stz_a_usage

Conversation

@CTalkobt
Copy link
Owner

@CTalkobt CTalkobt commented Jan 6, 2026

  • Safe case: When A value is NOT used after STA, both the LDA #$00 is removed and STA is converted to STZ
    • LDA #$00 / STA $1000 / STA $1001 → STZ $1000 / STZ $1001
  • Critical case: When A value IS used later (like in ADC), LDA #$00 is preserved and STA is still converted to STZ
    • LDA #$00 / STA $1000 / CLC / ADC $1001 / STA $1002 → LDA #$00 / STZ $1000 / CLC / ADC $1001 / STA $1002

The optimizer now correctly distinguishes between:

  • Instructions that USE A value (can't remove LDA): ADC, SBC, AND, ORA, EOR, CMP, BIT, PHA, TAX, TAY
  • Instructions that MODIFY A (safe to remove LDA): LDA, PLA, TXA, TYA

  - Safe case: When A value is NOT used after STA, both the LDA #$00 is removed and STA is converted to STZ
    - LDA #$00 / STA $1000 / STA $1001 → STZ $1000 / STZ $1001
  - Critical case: When A value IS used later (like in ADC), LDA #$00 is preserved and STA is still converted to STZ
    - LDA #$00 / STA $1000 / CLC / ADC $1001 / STA $1002 → LDA #$00 / STZ $1000 / CLC / ADC $1001 / STA $1002

  The optimizer now correctly distinguishes between:
  - Instructions that USE A value (can't remove LDA): ADC, SBC, AND, ORA, EOR, CMP, BIT, PHA, TAX, TAY
  - Instructions that MODIFY A (safe to remove LDA): LDA, PLA, TXA, TYA
@CTalkobt CTalkobt merged commit 6aa285a into main Jan 6, 2026
1 check passed
@CTalkobt CTalkobt deleted the feature/65c02_stz_a_usage branch January 6, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant