From b22183ba021d9ab3418d8f47545708597247e583 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 22 Nov 2019 02:35:31 +0100 Subject: strcpy, strcmp, write, read --- ft_strcmp.s | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'ft_strcmp.s') diff --git a/ft_strcmp.s b/ft_strcmp.s index 4c5aee7..216b56a 100644 --- a/ft_strcmp.s +++ b/ft_strcmp.s @@ -1,12 +1,35 @@ +.globl _ft_strcmp + _ft_strcmp: - mov eax, sp - mov ebx, sp + 8 + mov rax, rdi # s1 + mov rbx, rsi # s2 + xor rcx, rcx FT_STRCMP_LOOP: - cmp eax, 0 - jneq FT_STRCMP_LOOP - cmp ebx, 0 - jneq FT_STRCMP_LOOP - cmp eax, ebx - jeq FT_STRCMP_LOOP - sub eax, ebx + cmp byte ptr [rax + rcx], 0 + je FT_STRCMP_LOOP_END + cmp byte ptr [rbx + rcx], 0 + je FT_STRCMP_LOOP_END + mov dl, byte ptr [rax + rcx] + cmp dl, byte ptr [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] + 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 ret -- cgit