1: Use your Y register as the loop counter, counting down, while indexing up from 0 with the X register.
2: Load your X register with the *negative* of your string length, and adjust your base pointer to compensate. This is a bit tricker to pull off as a novice, but something similar is often done by advanced compilers for newer CPUs.
Incidentally, to test for equality with zero, you often don't need a CMP instruction - because the increment and decrement instructions set the N and Z flags for you. They just don't set C and V. This means the extra indexing of solution 1 should come for free:
Code: Select all
ldy #$0d
ldx #0
loop:
lda $081b,x
jsr CHROUT
inx ; Increment index
dey ; Decrement count
bne loop ; WHILE remaining characters, loop.
rts