-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrcmp.s
34 lines (28 loc) · 1005 Bytes
/
strcmp.s
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
BITS 64
global strcmp
strcmp:
push rbp ; Prologue
mov rbp, rsp ; (==enter)
mov rax, 0 ; result = 0
mov r9d, 0 ; char a = NULL
mov r10d, 0 ; char b = NULL
.loop: ; while
mov r9b, [rdi] ; a = str1
mov r10b, [rsi] ; b = str2
cmp byte r9b, r10b ; if (str1[i] < str2[i])
jl .first ; return -1
jg .second ; return 1
cmp r9b, 0 ; if (str1 == NULL)
je .end ; return 0
inc rdi ; str1++
inc rsi ; str2++
jmp .loop
.first:
mov rax, -1 ; return -1
jmp .end ; end
.second:
mov rax, 1 ; return 1
jmp .end ; end
.end:
leave
ret