aboutsummaryrefslogtreecommitdiff
path: root/ft_strcmp.s
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-11-23 02:54:37 +0100
committerCharles <sircharlesaze@gmail.com>2019-11-23 02:54:37 +0100
commitb4b6364c2fc4b14a0aaac406891c3880243a9733 (patch)
treee204b7a7cefd18c764cfbf8adb7f1491b689352c /ft_strcmp.s
parentc90117251f11e03452ae9808ff8626016c7958a1 (diff)
downloadlibasm-b4b6364c2fc4b14a0aaac406891c3880243a9733.tar.gz
libasm-b4b6364c2fc4b14a0aaac406891c3880243a9733.tar.bz2
libasm-b4b6364c2fc4b14a0aaac406891c3880243a9733.zip
refactored mandatory functions, to respect c calling convention
Diffstat (limited to 'ft_strcmp.s')
-rw-r--r--ft_strcmp.s50
1 files changed, 25 insertions, 25 deletions
diff --git a/ft_strcmp.s b/ft_strcmp.s
index da8bc1c..5be82a5 100644
--- a/ft_strcmp.s
+++ b/ft_strcmp.s
@@ -12,33 +12,33 @@
global _ft_strcmp
+; int ft_strcmp(const char *s1, const char *s2);
_ft_strcmp:
- mov rax, rdi
- mov rbx, rsi
- xor rcx, rcx
+ push r12
+ push r13
+ push rcx
+ mov r12, rdi ; s1
+ mov r13, rsi ; s2
+ mov rcx, -1 ; index
FT_STRCMP_LOOP:
- cmp byte [rax + rcx], 0
- je FT_STRCMP_LOOP_END
- cmp byte [rbx + rcx], 0
- je FT_STRCMP_LOOP_END
- mov dl, byte [rax + rcx]
- cmp dl, byte [rbx + rcx]
- jne FT_STRCMP_LOOP_END
inc rcx
- jmp FT_STRCMP_LOOP
+ cmp byte [r12 + rcx], 0 ; check and of s1
+ je FT_STRCMP_LOOP_END
+ mov dl, byte [r12 + rcx]
+ cmp dl, byte [r13 + rcx] ; s1[rcx] == s2[rcx]
+ je FT_STRCMP_LOOP
FT_STRCMP_LOOP_END:
- mov dl, byte [rax + rcx]
- cmp dl, byte [rbx + rcx]
- jl FT_STRCMP_S1_LOWER
- mov rdx, rax
- xor rax, rax
- mov al, [rdx + rcx]
- sub al, [rbx + rcx]
- ret
- FT_STRCMP_S1_LOWER:
- mov rdx, rax
- xor rax, rax
- mov al, [rbx + rcx]
- sub al, [rdx + rcx]
- neg eax
+
+ xor rax, rax
+ mov al, byte [r12 + rcx]
+ sub al, byte [r13 + rcx]
+ jnc FT_STRCMP_END ; jump end if no substraction overflow
+
+ neg al ; negate al to cancel overflow
+ neg eax ; negate the whole int since the function returns that type
+
+ FT_STRCMP_END:
+ pop rcx
+ pop r13
+ pop r12
ret