-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrchr.asm
More file actions
39 lines (32 loc) · 837 Bytes
/
strchr.asm
File metadata and controls
39 lines (32 loc) · 837 Bytes
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
;;
;; EPITECH PROJECT, 2025
;; B-ASM-400-LYN-4-1-asmminilibc-spencer.pay
;; File description:
;; strchr
;;
BITS 64
section .text
global strchr
global index
index:
strchr:
; Prologue
push rbp ; Save frame pointer
mov rbp, rsp ; Create new frame
loop_start:
cmp byte [rdi], sil ; Compare current char with target
je found ; Jump if found
cmp byte [rdi], 0 ; Check for string end
je not_found ; Jump if end reached
inc rdi ; Move to next character
jmp loop_start
found:
mov rax, rdi ; Return pointer to found character
jmp end
not_found:
xor rax, rax ; Return NULL
end:
; Epilogue
mov rsp, rbp ; Restore stack pointer
pop rbp ; Restore frame pointer
ret