Česky
Kamil Dudka

Tiny programs (C, C++, C#, ...)

File detail

Name:Downloadstrcmp.asm [Download]
Location: tiny > IAS > strcmp
Size:1019 B
Last modification:2007-08-29 17:44

Source code

bits 32
global myStrCmp
 
SECTION .text
 
myStrCmp:
	push ebp
	mov ebp,esp		; ebp - ukazatel na StackFrame
	push esi
	push edi
	push edx
	mov edi,[ebp+8]		; 1. Parametr do edi - dest
	mov esi,[ebp+12]	; 2. Parametr do esi - src
	xor edx,edx		; Navratova hodnota, 0...retezce jsou stejne
 
for:
	; Podminka cyklu FOR
	xor al,al		; al = 0
	cmp al,[edi]
	je endfor		; Konec retezce dest
	cmp al,[esi]
	je endfor		; Konec retezce src
 
	; Telo cyklu FOR
	mov al,[edi]
	cmp al,[esi]		; Porovnani znaku [edi],[esi]
	jbe neSrc
		inc edx		; Znak [edi] je vetsi
		jmp konec
	neSrc:
	jae neDest
		dec edx		; Znak [esi] je vetsi
		jmp konec
	neDest:
 
	; Inkrementace cyklu FOR
	inc esi
	inc edi
	jmp for
endfor:
 
	mov al,[edi]
	cmp al,[esi]		; Porovnani podle delky retezce
	jbe neSrcLen
		inc edx
		jmp konec
	neSrcLen:
	jae konec
		dec edx
konec:
 
	mov eax,edx		; Ulozeni navratove hodnoty do eax
	pop edx
	pop edi
	pop esi
	;mov esp,ebp		; Obnoveni esp - v tomto pripade neni nutne
	pop ebp			; Obnoveni puvodniho StackFrame
	ret