cstrstr.s

来自「avr的icc编译器的源代码」· S 代码 · 共 39 行

S
39
字号
; 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;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?