-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrrchr.asm
More file actions
42 lines (34 loc) · 955 Bytes
/
strrchr.asm
File metadata and controls
42 lines (34 loc) · 955 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
40
41
42
;;
;; EPITECH PROJECT, 2025
;; B-ASM-400-LYN-4-1-asmminilibc-spencer.pay
;; File description:
;; strrchr
;;
BITS 64
section .text
global strrchr
global rindex
rindex:
strrchr:
; Prologue
push rbp
mov rbp, rsp
xor rax, rax ; Initialize return value to NULL
loop_start:
cmp byte [rdi], 0 ; Check for end of string
je check_null ; If null terminator, check if we're looking for null
cmp byte [rdi], sil ; Compare current char with target
jne next_char ; If no match, continue
mov rax, rdi ; If match, save current position
next_char:
inc rdi ; Move to next character
jmp loop_start
check_null:
cmp byte [rdi], sil ; Check if we're looking for null terminator
jne end ; If not, we're done
mov rax, rdi ; If yes, save position of null terminator
end:
; Epilogue
mov rsp, rbp
pop rbp
ret