diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-11-23 00:28:03 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-11-23 00:28:03 +0100 |
| commit | c90117251f11e03452ae9808ff8626016c7958a1 (patch) | |
| tree | b4ef9f0f562d3394e23af4a698ad35964f18bc23 /ft_strcmp.s | |
| parent | 8e3a5ac569a3ccc1101b58fe8ef673f02b4961fb (diff) | |
| download | libasm-c90117251f11e03452ae9808ff8626016c7958a1.tar.gz libasm-c90117251f11e03452ae9808ff8626016c7958a1.tar.bz2 libasm-c90117251f11e03452ae9808ff8626016c7958a1.zip | |
Compiling with nasm
Diffstat (limited to 'ft_strcmp.s')
| -rw-r--r-- | ft_strcmp.s | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/ft_strcmp.s b/ft_strcmp.s index e04938a..da8bc1c 100644 --- a/ft_strcmp.s +++ b/ft_strcmp.s @@ -1,48 +1,44 @@ -# **************************************************************************** # -# # -# ::: :::::::: # -# ft_strcmp.s :+: :+: :+: # -# +:+ +:+ +:+ # -# By: cacharle <marvin@42.fr> +#+ +:+ +#+ # -# +#+#+#+#+#+ +#+ # -# Created: 2019/11/22 03:04:38 by cacharle #+# #+# # -# Updated: 2019/11/22 21:18:49 by cacharle ### ########.fr # -# # -# **************************************************************************** # +; **************************************************************************** ; +; ; +; ::: :::::::: ; +; ft_strcmp.s :+: :+: :+: ; +; +:+ +:+ +:+ ; +; By: cacharle <marvin@42.fr> +;+ +:+ +;+ ; +; +;+;+;+;+;+ +;+ ; +; Created: 2019/11/23 00:17:19 by cacharle ;+; ;+; ; +; Updated: 2019/11/23 00:17:19 by cacharle ;;; ;;;;;;;;.fr ; +; ; +; **************************************************************************** ; -.globl _ft_strcmp +global _ft_strcmp -# int ft_strcmp(const char *s1, const char *s2); _ft_strcmp: - mov rax, rdi # s1 - mov rbx, rsi # s2 + mov rax, rdi + mov rbx, rsi xor rcx, rcx FT_STRCMP_LOOP: - cmp byte ptr [rax + rcx], 0 + cmp byte [rax + rcx], 0 je FT_STRCMP_LOOP_END - cmp byte ptr [rbx + rcx], 0 + cmp byte [rbx + rcx], 0 je FT_STRCMP_LOOP_END - mov dl, byte ptr [rax + rcx] - cmp dl, byte ptr [rbx + rcx] + mov dl, byte [rax + rcx] + cmp dl, byte [rbx + rcx] jne FT_STRCMP_LOOP_END inc rcx jmp FT_STRCMP_LOOP FT_STRCMP_LOOP_END: - mov dl, byte ptr [rax + rcx] - cmp dl, byte ptr [rbx + rcx] + mov dl, byte [rax + rcx] + cmp dl, byte [rbx + rcx] jl FT_STRCMP_S1_LOWER - # s1 >= s2 mov rdx, rax xor rax, rax mov al, [rdx + rcx] sub al, [rbx + rcx] ret - # s1 < s2 FT_STRCMP_S1_LOWER: mov rdx, rax xor rax, rax mov al, [rbx + rcx] sub al, [rdx + rcx] - not eax # two's complement - inc eax + neg eax ret |
