Subversion Repositories Kolibri OS

Rev

Rev 3244 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3244 Rev 7577
Line 1... Line -...
1
; strlen function
-
 
2
;
1
;
3
; Copyright (c) 2003 Thomas Mathys
2
; Строковые функции
4
; killer@vantage.ch
-
 
5
;
3
;
6
; This program is free software; you can redistribute it and/or modify
-
 
7
; it under the terms of the GNU General Public License as published by
-
 
8
; the Free Software Foundation; either version 2 of the License, or
-
 
9
; (at your option) any later version.
-
 
10
;
-
 
11
; This program is distributed in the hope that it will be useful,
-
 
12
; but WITHOUT ANY WARRANTY; without even the implied warranty of
-
 
13
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-
 
14
; GNU General Public License for more details.
-
 
15
;
-
 
16
; You should have received a copy of the GNU General Public License
-
 
17
; along with this program; if not, write to the Free Software
-
 
18
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
 
19
;
-
 
20
;%ifndef _STRLEN_INC
-
 
21
;%define _STRLEN_INC
-
 
22
 
-
 
Line 23... Line -...
23
 
-
 
24
;********************************************************************
-
 
25
;       returns the length of an asciiz string
-
 
26
;       input           :       esi = pointer to string
-
 
27
;       output          :       eax = string length
-
 
28
;       destroys        :       nothing
-
 
29
;********************************************************************
4
 
30
strlen:
5
;output:
31
	push	ecx edi
6
; eax = strlen
32
	pushfd
7
align 4
33
	cld				; !
8
proc str_len, str1:dword
34
	mov	ecx,-1
-
 
35
	mov	edi,esi 		; find terminating zero
9
	mov eax,[str1]
36
	xor	al,al
10
	@@:
37
	repne	scasb
-
 
38
	mov	eax,edi 		; calculate string length
11
		cmp byte[eax],0
39
	sub	eax,esi
12
		je @f
40
	dec	eax
13
		inc eax
-
 
14
		jmp @b
41
	popfd
15
	@@:
42
	pop	edi ecx
16
	sub eax,[str1]
-
 
17
	ret
Line 43... Line -...
43
	ret
-
 
44
 
-
 
45
 
18
endp
46
 
-
 
47
; linlen function
19
 
48
;
-
 
49
; Copyright (c) 2009 Igor Afanasiev
20
align 4
50
 
21
proc str_cat uses eax ecx edi esi, str1:dword, str2:dword
51
linlen:
-
 
52
	push	ecx edi
-
 
53
	pushfd
22
	mov esi,[str2]
54
	cld
23
	stdcall str_len,esi
55
	mov	ecx,eax
-
 
56
	inc ecx
24
	mov ecx,eax
57
	mov	edi,esi 		; find terminating zero
-
 
58
	mov	al,13
-
 
59
	repne	scasb
25
	inc ecx
60
	mov	eax,edi 		; calculate string length
26
	mov edi,[str1]
61
	sub	eax,esi
27
	stdcall str_len,edi
62
	dec	eax
28
	add edi,eax
63
	popfd
29
	cld
-
 
30
	repne movsb
Line 64... Line 31...
64
	pop	edi ecx
31
	ret
65
	ret
32
endp
66
 
33
 
67
;description:
34
;description:
Line 77... Line 44...
77
	;xor eax,eax
44
	;xor eax,eax
78
	mov edi,[str0]
45
	mov edi,[str0]
79
	mov esi,[str1]
46
	mov esi,[str1]
80
	cld
47
	cld
81
	@@:
48
	@@:
82
		mov al,[esi]
49
		lodsb
83
		cmp al,0
50
		or al,al
84
		je .e1
51
		jz .e1
85
		inc esi
-
 
86
		scasb ;сравниваем символы
52
		scasb ;сравниваем символы
87
	jz @b ;если совпали, то переходим к сравнению следующих
53
	jz @b ;если совпали, то переходим к сравнению следующих
88
	;сюда попадаем если строки не совпали
54
	;сюда попадаем если строки не совпали
89
	sub al,[edi-1]
55
	sub al,[edi-1]
90
	.e1: ;сюда попадаем если строка str1 (esi) закончилась
56
	.e1: ;сюда попадаем если строка str1 (esi) закончилась
91
	ret
57
	ret
92
endp
58
endp
Line -... Line 59...
-
 
59
 
-
 
60
;input:
-
 
61
; eax - число
-
 
62
; edi - буфер для строки
-
 
63
; len - длинна буфера
-
 
64
;output:
-
 
65
align 4
-
 
66
proc convert_int_to_str uses eax ecx edx edi esi, len:dword
-
 
67
	mov esi,[len]
-
 
68
	add esi,edi
-
 
69
	dec esi
-
 
70
	call .str
-
 
71
	ret
-
 
72
endp
-
 
73
 
-
 
74
align 4
-
 
75
.str:
-
 
76
	mov ecx,10
-
 
77
	cmp eax,ecx
-
 
78
	jb @f
-
 
79
		xor edx,edx
-
 
80
		div ecx
-
 
81
		push edx
-
 
82
		;dec edi  ;смещение необходимое для записи с конца строки
-
 
83
		call .str
-
 
84
		pop eax
-
 
85
	@@:
-
 
86
	cmp edi,esi
-
 
87
	jge @f
-
 
88
		or al,0x30
-
 
89
		stosb
-
 
90
		mov byte[edi],0 ;в конец строки ставим 0, что-бы не вылазил мусор
-
 
91
	@@:
93
92
	ret