2 ; Ullrich von Bassewitz, 15.09.2000
4 ; int memcmp (const void* p1, const void* p2, size_t count);
8 .import popax, popptr1, return0
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
31 ;ldy #$00 ; Initialize pointer (Y=0 guaranteed by popptr1)
32 ldx ptr3 ; Load low counter byte into X
34 ; Head of compare loop: Test for the end condition
36 Loop: inx ; Bump low byte of (-count-1)
37 beq BumpHiCnt ; Jump on overflow
43 bne NotEqual ; Jump if bytes not equal
47 iny ; Increment pointer
49 inc ptr1+1 ; Increment high bytes
51 bne Loop ; Branch always (pointer wrap is illegal)
53 ; Entry on low counter byte overflow
56 inc ptr3+1 ; Bump high byte of (-count-1)
57 bne Comp ; Jump if not done
58 jmp return0 ; Count is zero, areas are identical
60 ; Not equal, check which one is greater
64 ldx #$FF ; Make result negative
68 ldx #$01 ; Make result positive