String Comparison for PASCAL style Strings
Posted: Sat Jul 30, 2005 9:28 pm
Source code is in MERLIN format be should be easy to adapt
A slightly shorter and faster 65C02 version of this code can be created by removing lines 14 and 27, and removing the ",Y" from the end of every line EXCEPT 21 and 22.
Code: Select all
1 * String Comparison Routine for PASCAL strings
2 * INPUT *
3 * Pointer to First String in STRING1, STRING1+1
4 * Pointer to Second String in STRING2, STRING2+1
5 * STRING1 and STRING2 must be located on the ZERO PAGE
6 * TEMP can be anywhere in memory
7 * OUTPUT *
8 * If String1 < String2 then carry clear; else carry set
9 * If String1 = String 2 then Z set; else Z clear
10 * Destroys A-REG and Y-REG; X-REG unchanged
11 STRING1 EQU 6
12 STRING2 EQU 8
13 TEMP EQU 9
14 PSTRCMP LDY #0
15 LDA (STRING1),Y
16 CMP (STRING2),Y
17 BCC :1
18 LDA (STRING2),Y
19 :1 STA TEMP
20 LDY #1
21 :2 LDA (STRING1),Y
22 CMP (STRING2),Y
23 BNE :3
24 INY
25 CPY TEMP
26 BCC :2
27 LDY #0
28 LDA (STRING1),Y
29 CMP (STRING2),Y
30 :3 RTS