From 88af64a057534031c75048cf59843a4534900a55 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 9 Dec 2025 12:43:29 +0100 Subject: [PATCH] feat(strcmp): adding the function strcmp function This function is already commented --- src/ft_strcmp.s | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/ft_strcmp.s diff --git a/src/ft_strcmp.s b/src/ft_strcmp.s new file mode 100644 index 0000000..2da7f09 --- /dev/null +++ b/src/ft_strcmp.s @@ -0,0 +1,29 @@ +segment .note.GNU-stack + +section .text + global ft_strcmp + +ft_strcmp: + xor eax, eax ; init to 0 + xor edx, edx ; init to 0 + cmp rdi, 0 ; check s1 NULL + je .exit ; exit if true + cmp rsi, 0 ; check s2 NULL + je .exit ; exit if true + jmp .loop ; go to the loop + +.loop: + movzx ecx, BYTE [rdi + rdx] ; move and change all previous bytes to 0 (zero extanded) + movzx r8d, BYTE [rsi + rdx] ; move and change all previous bytes to 0 (zero extanded) + mov r9d, ecx ; tmp value + or r9b, r8b ; check if one of byte is NULL + je .exit ; exit if it's true + inc rdx ; counter + 1 + cmp cl, r8b ; compare les 2 bytes lu (cl end of ecx 2 last bytes) + je .loop ; loop again if it's true + movzx eax, r8b ; move and change all previous bytes to 0 (zero extanded) + sub ecx, eax ; ecx - eax (r8b) + mov eax, ecx ; move the ecx in the return value + +.exit: + ret ; return rax value