-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrcasecmp.asm
56 lines (41 loc) · 1.32 KB
/
strcasecmp.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
BITS 64 ; 64-bits mode
section .text
global strcasecmp ; The "strcasecmp" function must be callable outside
strcasecmp:
; "rdi" corresponds to the first string
; "rsi" corresponds to the second string
mov al, [rdi] ; Stores the current character (first string)
mov ah, [rsi] ; Stores the current character (second string)
cmp al, 0 ; Checks if the first string is finished
je strcasecmp_end_first
cmp ah, 0 ; Checks if the second string is finished
je strcasecmp_end_second
or al, 32 ; Converts the current character to lowercase (first string)
or ah, 32 ; Converts the current character to lowercase (second string)
cmp al, ah ; Compares the current characters
je strcasecmp_equal
ja strcasecmp_greater
jb strcasecmp_lower
strcasecmp_equal:
inc rdi ; Moves to the next character (first string)
inc rsi ; Moves to the next character (second string)
jmp strcasecmp ; Recursivity
strcasecmp_greater:
mov rax, 1
ret
strcasecmp_lower:
mov rax, -1
ret
strcasecmp_end_first:
cmp ah, 0 ; Checks if the both strings are finished
je strcasecmp_end_both
mov rax, -1
ret
strcasecmp_end_second:
cmp al, 0 ; Checks if the both strings are finished
je strcasecmp_end_both
mov rax, 1
ret
strcasecmp_end_both:
mov rax, 0
ret