www.pudn.com > iccavr_lib.rar > cstrstr.s, change:2003-11-08,size:915b


; char *cstrstr(char *ramstr, const char *romstr) 
; ja 2003-02-21 
; 
; uses R0,R1,R16,R17,R18,R19,R26,R27,R30,R31 
; 
; note: cstrstr will not find an empty romstr 
; 
_cstrstr:: 
cstrstr1: 
	mov	R30,R18	; (re)load 
	mov 	R31,R19	; rom pointer 
	mov 	R26,R16	; and 
	mov 	R27,R17	; ram pointer 
cstrstr2: 
	lpm			; get rom char 
	tst	R0		; end of romstr? 
	 breq	cstrstr3	; yes = found ... 
	adiw	R30,1		; inc rom pointer 
	ld	R1,X+ 	; get ram char 
	tst	R1		; end of ramstr? 
	 breq	cstrstr4	; yes = not found ... 
	cp	R1,R0		; chars are equal? 
	 breq	cstrstr2	; go next rom char ... 
	subi	R16,0xFF	; else 
	sbci	R17,0xFF	; inc ram pointer 
	rjmp	cstrstr1	; go next ram char ... 
; 
cstrstr3:			; end of romstr: 
	cp	R30,R18	; romstr must not 
	cpc	R31,R19	; be emptfy 
	 brne	cstrstr99	; ... 
cstrstr4:	     		; romstr not found: 
	ldi	R16,0		; 
	ldi	R17,0		; return NULL pointer 
cstrstr99: 
	ret 
; 
;eof;