2 ; Ullrich von Bassewitz, 25.05.2000
4 ; int strncmp (const char* s1, const char* s2, unsigned n);
9 .importzp ptr1, ptr2, ptr3
14 ; Convert the given counter value in a/x from a downward counter into an
15 ; upward counter, so we can increment the counter in the loop below instead
16 ; of decrementing it. This adds some overhead now, but is cheaper than
17 ; executing a more complex test in each iteration of the loop. We do also
18 ; correct the value by one, so we can do the test on top of the loop.
26 ; Get the remaining arguments
35 ;ldy #0 Y=0 guaranteed by popptr1
37 ; Start of compare loop. Check the counter.
40 beq IncHi ; Increment high byte
42 ; Compare a byte from the strings
46 bne NotEqual ; Jump if strings different
48 beq Equal1 ; Jump if EOS reached, a/x == 0
50 ; Increment the pointers
56 bne Loop ; Branch always
61 bne Comp ; Jump if counter not zero
63 ; Exit code if strings are equal. a/x not set
69 ; Exit code if strings not equal
73 ldx #$FF ; Make result negative
76 L1: ldx #$01 ; Make result positive