1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-17 09:07:32 +00:00
cc65/libsrc/common/memchr.s
cuz 32389dc678 Optimization
git-svn-id: svn://svn.cc65.org/cc65/trunk@2151 b7a2c559-68d2-44c3-8de9-860c34a00d81
2003-05-05 17:19:48 +00:00

58 lines
1.0 KiB
ArmAsm

;
; Ullrich von Bassewitz, 2003-05-05
;
; void* __fastcall__ memchr (const void* p, int c, size_t n);
;
.export _memchr
.import popax, return0
.importzp ptr1, ptr2
.proc _memchr
eor #$FF
sta ptr2
txa
eor #$FF
sta ptr2+1 ; Save ones complement of n
jsr popax ; get c
pha
jsr popax ; get p
sta ptr1
stx ptr1+1
ldy #$00
pla ; Get c
ldx ptr2 ; Use X as low counter byte
L1: inx
beq L3
L2: cmp (ptr1),y
beq found
iny
bne L1
inc ptr1+1
bne L1 ; Branch always
L3: inc ptr2+1 ; Bump counter high byte
bne L2
; Not found, return NULL
notfound:
jmp return0
; Found, return pointer to char
found: ldx ptr1+1 ; get high byte of pointer
tya ; low byte offset
clc
adc ptr1
bcc L9
inx
L9: rts
.endproc