AppleIIAsm-Collection/source/disk20_minidisk_A/T.STRCOMP.SUB.MIN
nathanriggs 82d0e74c1a 0.3.1 updates
some minor bugfixes, directory shuffling, added demo and utility disks
2019-01-26 21:02:17 -05:00

48 lines
1.3 KiB
Plaintext

STRCMP
PLA
STA RETADR
PLA
STA RETADR+1
PLA
STA ADDR2
PLA
STA ADDR2+1
PLA
STA ADDR1
PLA
STA ADDR1+1
LDY #0
LDA (ADDR1),Y ; GET LENGTH OF STRING 1
CMP (ADDR2),Y
BCC :BEGCMP ; IF STRING 2 IS SHORTER THEN
LDA (ADDR2),Y ; USE ITS LENGTH INSTEAD
:BEGCMP
TAX ; X IS LENGTH OF SHORTER STRING
BEQ :TSTLEN ; BR IF LENGTH IS 0
LDY #1 ; POINT AT FIRST CHAR OF STRINGS
:CMPLP
LDA (ADDR1),Y
CMP (ADDR2),Y
BNE :EXIT ; BR IF CHARS NOT EQUAL
; Z,C WILL BE PROPERLY SET
; OR CLEARED
; ELSE
INY ; NEXT CHAR
DEX ; DECREMENT COUNTER
BNE :CMPLP ; CONTINUE UNTIL ALL BYTES PAIRED
:TSTLEN
LDY #0 ; COMPARE LENGTHS
LDA (ADDR1),Y
CMP (ADDR2),Y ; SET OR CLEAR THE FLAGS
:EXIT
LDA RETADR+1
PHA
LDA RETADR
PHA
LDY #0
LDA (ADDR1),Y ; GET STR1 LENGTH
TAX ; RETURN IN X
LDA (ADDR2),Y ; STR2 LENGTH
TAY ; RETURN IN Y
RTS