1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-06 13:29:01 +00:00
cc65/libsrc/common/strchr.s
uz 53dd513176 This commit was generated by cvs2svn to compensate for changes in r2,
which included commits to RCS files with non-trunk default branches.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3 b7a2c559-68d2-44c3-8de9-860c34a00d81
2000-05-28 13:40:48 +00:00

42 lines
728 B
ArmAsm

;
; Ullrich von Bassewitz, 31.05.1998
;
; const char* strchr (const char* s, int c);
;
.export _strchr
.import popax
.importzp ptr1, tmp1
_strchr:
sta tmp1 ; Save c
jsr popax ; get s
sta ptr1
stx ptr1+1
ldy #0
scloop: lda (ptr1),y ; get next char
beq strz ; jump if end of string
cmp tmp1 ; found?
beq strf ; jump if yes
iny
bne scloop
inc ptr1+1
bne scloop ; jump always
; found, calculate pointer to c
strf: ldx ptr1+1 ; get high byte of pointer
tya ; low byte offset
clc
adc ptr1
bcc str1
inx
str1: rts
; not found, return zero
strz: tax ; return 0
rts