feat(strcmp): adding the function strcmp function
This function is already commented
This commit is contained in:
parent
f667e27396
commit
88af64a057
1 changed files with 29 additions and 0 deletions
29
src/ft_strcmp.s
Normal file
29
src/ft_strcmp.s
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue