2 ; Ullrich von Bassewitz, 15.09.2000
4 ; int memcmp (const void* p1, const void* p2, size_t count);
9 .importzp ptr1, ptr2, ptr3
13 ; Calculate (-count-1) and store it into ptr3. This is some overhead here but
14 ; saves time in the compare loop
22 ; Get the pointer parameters
33 ldx ptr3 ; Load low counter byte into X
34 ldy #$00 ; Initialize pointer
36 ; Head of compare loop: Test for the end condition
38 Loop: inx ; Bump low byte of (-count-1)
39 beq BumpHiCnt ; Jump on overflow
45 bne NotEqual ; Jump if bytes not equal
49 iny ; Increment pointer
51 inc ptr1+1 ; Increment high bytes
53 bne Loop ; Branch always (pointer wrap is illegal)
55 ; Entry on low counter byte overflow
58 inc ptr3+1 ; Bump high byte of (-count-1)
59 bne Comp ; Jump if not done
60 jmp return0 ; Count is zero, areas are identical
62 ; Not equal, check which one is greater
66 ldx #$FF ; Make result negative
70 ldx #$01 ; Make result positive