-
Notifications
You must be signed in to change notification settings - Fork 0
/
strpbrk.asm
83 lines (66 loc) · 1.04 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
SECTION .text
GLOBAL strpbrk
strchr:
push rbp
mov rbp, rsp
mov rax, 0
start_strchr:
cmp byte[rdi], 0
je not_found_strchr
cmp byte[rdi], sil
je found_strchr
add rdi, 1
jmp start_strchr
not_found_strchr:
cmp byte[rdi], sil
je found_strchr
leave
ret 0
found_strchr:
mov rax, rdi
leave
ret
;char *strpbrk(register const char *s, register const char *accept)
;{
; while (*s != '\0')
; if (strchr(accept, *s) == NULL)
; s++;
; else
; return (char *)s;
; return NULL;
;}
strpbrk:
push rbp
mov rbp, rsp
mov rax, 0
mov rdx, 0
cmp rdi, 0
je end_null
cmp rsi, 0
je end_null
invert_rdi_rsi:
mov rdx, rsi
mov rsi, rdi
mov rdi, rdx
jmp my_for_strpbrk
my_for_strpbrk:
cmp byte[rsi], 0
je end_null
push rdi
push rsi
mov rsi, [rsi]
call strchr
pop rsi
pop rdi
cmp rax, 0
jne end
inc rsi
jmp my_for_strpbrk
end_null:
mov rax, 0
leave
ret
end:
mov rax, rsi
leave
ret