-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrcmp.asm
More file actions
52 lines (41 loc) · 916 Bytes
/
strcmp.asm
File metadata and controls
52 lines (41 loc) · 916 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
43
44
45
46
47
48
49
50
51
52
;;
;; EPITECH PROJECT, 2025
;; B-ASM-400-LYN-4-1-asmminilibc-spencer.pay
;; File description:
;; strcmp
;;
BITS 64
section .text
global strcmp
strcmp:
; Prologue
push rbp ; Save frame pointer
mov rbp, rsp
push rcx ; Save rcx since we modify it
compare_loop:
; Load char from both strings
mov al, byte [rdi]
mov cl, byte [rsi]
; Jump to not_equal if characters are different
cmp al, cl
jne not_equal
; Check for end of string and leave loop if so
cmp al, 0
je equal
; Move to next chars and reloop
inc rdi
inc rsi
jmp compare_loop
not_equal:
movzx rax, al ; Zero-extend chars for comparison
movzx rcx, cl
sub rax, rcx ; Calculate difference
jmp end
equal:
xor rax, rax ; Return 0 for equal strings
end:
; Epilogue
pop rcx
mov rsp, rbp
pop rbp
ret