-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrstr.asm
55 lines (47 loc) · 1.22 KB
/
strstr.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
bits 64
global strstr
section .text
is_word:
begin:
mov cl, byte [rdi]
mov dl, byte [rsi]
cmp dl, 0
je success
cmp cl, 0
je failure
cmp cl, dl
je incr
jmp failure
incr:
inc rdi
inc rsi
jmp begin
success:
mov rax, 0
ret
failure:
mov rax, 1
ret
strstr:
mov r8, rdi ; Save src
mov r9, rsi ; Save to_find
;cmp rdi, rsi
;je success_str
cmp byte [rsi], 0
je success_str
begin_str:
cmp byte [r8], 0
je failure_str
mov rdi, r8
mov rsi, r9
call is_word
cmp rax, 0
je success_str
inc r8
jmp begin_str
success_str:
mov rax, r8
ret
failure_str:
xor rax, rax
ret