2000-05-28 13:40:48 +00:00
|
|
|
;
|
2000-09-15 17:23:19 +00:00
|
|
|
; Ullrich von Bassewitz, 15.09.2000
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; int memcmp (const void* p1, const void* p2, size_t count);
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _memcmp
|
2018-05-20 13:30:18 +00:00
|
|
|
.import popax, popptr1, return0
|
2013-05-09 11:56:54 +00:00
|
|
|
.importzp ptr1, ptr2, ptr3
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
_memcmp:
|
2000-09-15 17:23:19 +00:00
|
|
|
|
2020-12-27 23:22:12 +00:00
|
|
|
; Calculate a special count, and store it into ptr3. That is some overhead here,
|
|
|
|
; but saves time in the compare loop
|
2000-09-15 17:23:19 +00:00
|
|
|
|
2020-11-01 21:59:07 +00:00
|
|
|
inx
|
|
|
|
stx ptr3+1
|
|
|
|
tax
|
|
|
|
inx
|
|
|
|
stx ptr3 ; Save count with each byte incremented separately
|
2000-09-15 17:23:19 +00:00
|
|
|
|
|
|
|
; Get the pointer parameters
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr popax ; Get p2
|
|
|
|
sta ptr2
|
|
|
|
stx ptr2+1
|
2018-05-20 13:30:18 +00:00
|
|
|
jsr popptr1 ; Get p1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-09-15 17:23:19 +00:00
|
|
|
; Loop initialization
|
|
|
|
|
2018-05-20 13:30:18 +00:00
|
|
|
;ldy #$00 ; Initialize pointer (Y=0 guaranteed by popptr1)
|
2020-12-27 23:22:12 +00:00
|
|
|
ldx ptr3 ; Load inner counter byte into .X
|
2000-09-15 17:23:19 +00:00
|
|
|
|
|
|
|
; Head of compare loop: Test for the end condition
|
|
|
|
|
2020-12-27 23:22:12 +00:00
|
|
|
Loop: dex
|
|
|
|
beq BumpHiCnt ; Jump on end of inner count
|
2000-09-15 17:23:19 +00:00
|
|
|
|
|
|
|
; Do the compare
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
Comp: lda (ptr1),y
|
|
|
|
cmp (ptr2),y
|
|
|
|
bne NotEqual ; Jump if bytes not equal
|
2000-09-15 17:23:19 +00:00
|
|
|
|
|
|
|
; Bump the pointers
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
iny ; Increment pointer
|
|
|
|
bne Loop
|
|
|
|
inc ptr1+1 ; Increment high bytes
|
|
|
|
inc ptr2+1
|
|
|
|
bne Loop ; Branch always (pointer wrap is illegal)
|
2000-09-15 17:23:19 +00:00
|
|
|
|
2020-12-27 23:22:12 +00:00
|
|
|
; Entry on inner loop end
|
2000-09-15 17:23:19 +00:00
|
|
|
|
|
|
|
BumpHiCnt:
|
2020-12-27 23:22:12 +00:00
|
|
|
dec ptr3+1
|
2013-05-09 11:56:54 +00:00
|
|
|
bne Comp ; Jump if not done
|
|
|
|
jmp return0 ; Count is zero, areas are identical
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Not equal, check which one is greater
|
|
|
|
|
2000-09-15 17:23:19 +00:00
|
|
|
NotEqual:
|
2013-05-09 11:56:54 +00:00
|
|
|
bcs Greater
|
|
|
|
ldx #$FF ; Make result negative
|
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-09-15 17:23:19 +00:00
|
|
|
Greater:
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #$01 ; Make result positive
|
|
|
|
rts
|