-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrpbrk.asm
53 lines (36 loc) · 1.06 KB
/
strpbrk.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
BITS 64 ; 64-bits mode
section .text
global strpbrk ; The "strpbrk" function must be callable outside
strpbrk:
; "rdi" corresponds to the string
; "rsi" corresponds to the query
cmp [rdi], byte 0
je strpbrk_end ; At the end of the string, returns NULL
mov rdx, rsi ; Saves the query address
call strpbrk_search_loop
mov rsi, rdx ; Restores the query address
cmp bl, 1
je strpbrk_found ; If the character is found, returns a pointer to current character (string)
inc rdi ; Moves to the next character (string)
jmp strpbrk ; Recursivity
strpbrk_found:
mov rax, rdi
ret
strpbrk_end:
mov rax, 0
ret
strpbrk_search_loop:
cmp [rsi], byte 0
je strpbrk_search_end ; At the end of the query, returns "0"
mov al, [rdi]
mov ah, [rsi]
cmp al, ah
je strpbrk_search_found ; If the character is found, returns "1"
inc rsi ; Moves to the next character (query)
jmp strpbrk_search_loop ; Recursivity
strpbrk_search_end:
mov bl, 0
ret
strpbrk_search_found:
mov bl, 1
ret