In the length-byte-before-string comparison routine above:
1. With the EQUs above, TEMP overlaps with the high byte of the STRING2 pointer.
2. It doesn't compare the last byte of the string when the length byte is greater than 1.
3. If both length bytes are $00, it can loop endlessly.
A couple of optimizations are also possible: (a) X can be used instead of TEMP, and (b) the LDY #1 can be eliminated. Here is the updated code:
Code:
LDY #0
LDA (STRING1),Y
CMP (STRING2),Y
BCC :1
:1 LDA (STRING2),Y
TAX
BEQ :3
:2 INY
LDA (STRING1),Y
CMP (STRING1),Y
BNE :3
DEX
BNE :2
LDA (STRING1,X)
CMP (STRING2,X)
:3 RTS
Here is a slightly optimized version of the routine that compares strings (of any length) terminated by $00. Same inputs and outputs as above.
Code:
LDY #0
:1 LDA (STRING1),Y
BEQ :2
CMP (STRING2),Y
BNE :3
INY ; note: C=1 since CMP was equal
BNE :1
INC STRING1+1
INC STRING2+1
BCS :1 ; always branches
:2 CMP (STRING2),Y
:3 RTS