Adds strcmp() (note: much different than strcmp in C)
This commit is contained in:
@@ -5,6 +5,7 @@ section .text
|
||||
global strcpy
|
||||
global strcat
|
||||
global strclr
|
||||
global strcmp
|
||||
|
||||
;----- strlen(*str[]) -----;
|
||||
; Gets the length of given string
|
||||
@@ -102,3 +103,43 @@ strclr:
|
||||
cld
|
||||
rep stosb
|
||||
ret
|
||||
|
||||
;----- strcmp(*str1[], *str2[]) -----;
|
||||
; Compares str2 against str1
|
||||
; Return values:
|
||||
; 0 Two strings are the same, OR str1 or str2 is empty
|
||||
; Length of str1 str2 is longer than str1, but no difference was found in between str1 and str2 -up to the point str1 ended-
|
||||
; Anything else Position (index+1) where str1 and str2 differ
|
||||
; Used registers:
|
||||
; rax* (ret)
|
||||
; rdi Pointer to str1
|
||||
; rsi Pointer to str2
|
||||
; rcx* Counter for scasb
|
||||
; rdx* Length of str1
|
||||
; r8* Backup for rdi
|
||||
strcmp:
|
||||
mov rax, -1
|
||||
cmp byte [rdi], EOS
|
||||
je .equal
|
||||
cmp byte [rsi], EOS
|
||||
je .equal
|
||||
|
||||
mov r8, rdi
|
||||
call strlen
|
||||
mov rcx, rax
|
||||
mov rdx, rax
|
||||
mov rdi, r8
|
||||
cld
|
||||
repe cmpsb
|
||||
je .equal
|
||||
mov rax, rdx
|
||||
sub rax, rcx
|
||||
jmp .quit
|
||||
|
||||
.equal:
|
||||
cmp byte [rsi], EOS
|
||||
jne .quit
|
||||
mov rax, -1
|
||||
|
||||
.quit:
|
||||
ret
|
||||
|
Reference in New Issue
Block a user