aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--ft_atoi_base.s114
-rw-r--r--ft_list_push_front.s22
-rw-r--r--ft_list_remove_if.s0
-rw-r--r--ft_list_size.s25
-rw-r--r--ft_list_sort.s36
-rw-r--r--ft_read.s3
-rw-r--r--ft_strcmp.s3
-rw-r--r--ft_strcpy.s3
-rw-r--r--ft_strdup.s3
-rw-r--r--ft_strlen.s5
-rw-r--r--ft_write.s3
-rw-r--r--main.c18
13 files changed, 200 insertions, 37 deletions
diff --git a/.gitignore b/.gitignore
index 098f1c1..0291a3f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,5 @@ a.out
*.a
test.s
test.c
+t.c
+t.s
diff --git a/ft_atoi_base.s b/ft_atoi_base.s
index bc675af..6245765 100644
--- a/ft_atoi_base.s
+++ b/ft_atoi_base.s
@@ -6,53 +6,113 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/11/22 03:59:15 by cacharle #+# #+# #
-# Updated: 2019/11/22 05:20:12 by cacharle ### ########.fr #
+# Updated: 2019/11/22 21:18:08 by cacharle ### ########.fr #
# #
# **************************************************************************** #
.globl _ft_atoi_base
+.globl _check_base
+# int ft_atoi_base(const char*, const char*);
_ft_atoi_base:
+ push rbp # save previous stackframe
+ mov rbp, rsp # create new one
+
mov rbx, rdi # rbx = str
mov rcx, rsi # rcx = base
- xor rdx, rdx # rdx = 0
-
- # remove spaces
- FT_ATOI_BASE_SPACE_LOOP:
- cmp byte ptr [rbx], 20h # if space jump next
- je NEXT
+ mov rdi, rcx
+ call _check_base
+ cmp rax, 0
+ je CHECK_BASE_ERROR
- mov dl, byte ptr [rbx] # if \t\n\r\v\f jump next
- sub dl, 9h
- cmp dl, 5h
- jl NEXT
+ mov rdi, rcx
+ call _ft_strlen
+ #mov r8, rax # r8 = radix
+ #mov rax, r8
- jmp FT_ATOI_BASE_SPACE_LOOP_END # if all above false end loop
- NEXT: # next iteration
- inc rbx
- jmp FT_ATOI_BASE_SPACE_LOOP
+ xor rdx, rdx # rdx = 0
+ FT_ATOI_BASE_SPACE_LOOP: # remove spaces
+ mov rdi, [rbx]
+ call ft_isspace
+ cmp rax, 1
+ jne FT_ATOI_BASE_SPACE_LOOP_END
+ inc rbx
+ jmp FT_ATOI_BASE_SPACE_LOOP
FT_ATOI_BASE_SPACE_LOOP_END:
xor rax, rax # rax = 0
xor rdx, rdx # rdx = 0
-
FT_ATOI_BASE_LOOP:
- # while isdigit
- cmp byte ptr [rbx], 30h
- jl FT_ATOI_BASE_END # if *rbx < '0' jmp end
+ cmp byte ptr [rbx], 30h # while isdigit
+ jl FT_ATOI_BASE_END # if *rbx < '0' jmp end
cmp byte ptr [rbx], 39h
- ja FT_ATOI_BASE_END # if *rbx > '9' jmp end
+ ja FT_ATOI_BASE_END # if *rbx > '9' jmp end
- imul eax, 10 # eax *= 10
- # dl = *str & 0x0F
+ imul eax, 10 # eax *= 10, shift previous digits
mov dl, byte ptr [rbx]
- and dl, 0x0F
- add eax, edx # eax += dl (digit)
- inc rbx # next char
+ and dl, 0x0F # char to digit
+ add eax, edx # insert as first digit
+ inc rbx
jmp FT_ATOI_BASE_LOOP
-
FT_ATOI_BASE_END:
- ret
+ pop rbp
+ ret
+_base_pos:
+ mov rcx, rsi
+ xor rax, rax
+ BASE_POS_LOOP:
+ cmp byte ptr [rdi + rax], 0
+ je BASE_POS_NOT_FOUND
+ cmp cl, byte ptr [rdi + rax]
+ je BASE_POS_FOUND
+ inc eax
+ jmp BASE_POS_LOOP
+ BASE_POS_NOT_FOUND:
+ mov eax, 0xFFFFFFFF
+ BASE_POS_FOUND:
+ ret
+_check_base:
+ push rbx
+ mov rbx, rsp
+
+ mov rbx, rdi # rbx = str
+
+ call _ft_strlen # f strlen(rbx) < 2
+ cmp eax, 2
+ jl CHECK_BASE_ERROR
+
+ CHECK_BASE_LOOP:
+ cmp byte ptr [rbx], 2bh # *rbx == '-' || *rbx == '+'
+ je CHECK_BASE_ERROR
+ cmp byte ptr [rbx], 2dh
+ je CHECK_BASE_ERROR
+ call ft_isspace
+ cmp rax, 1
+ je CHECK_BASE_ERROR
+
+ inc rbx
+ cmp byte ptr [rbx], 0h
+ jne CHECK_BASE_LOOP
+ mov rax, 1
+ pop rbx
+ ret
+ CHECK_BASE_ERROR:
+ xor rax, rax
+ pop rbx
+ ret
+
+ft_isspace:
+ cmp byte ptr [rdi], 20h # if space jump next
+ je ISSPACE_TRUE_END
+ mov dl, byte ptr [rdi] # if \t\n\r\v\f jump next
+ sub dl, 9h
+ cmp dl, 5h
+ jl ISSPACE_TRUE_END
+ xor rax, rax
+ ret
+ ISSPACE_TRUE_END:
+ mov rax, 1
+ ret
diff --git a/ft_list_push_front.s b/ft_list_push_front.s
new file mode 100644
index 0000000..835aa2c
--- /dev/null
+++ b/ft_list_push_front.s
@@ -0,0 +1,22 @@
+# **************************************************************************** #
+# #
+# ::: :::::::: #
+# ft_list_push_front.s :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2019/11/22 20:55:08 by cacharle #+# #+# #
+# Updated: 2019/11/22 21:17:45 by cacharle ### ########.fr #
+# #
+# **************************************************************************** #
+
+.globl _ft_list_push_front
+
+# void ft_list_push_front(t_list **begin_list, void *data);
+_ft_list_push_front:
+ cmp rdi, 0
+ je FT_LIST_PUSH_FRONT_END
+ mov [rsi + 8], [rdi]
+ mov [rdi], rsi
+ FT_LIST_PUSH_FRONT_END:
+ ret
diff --git a/ft_list_remove_if.s b/ft_list_remove_if.s
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ft_list_remove_if.s
diff --git a/ft_list_size.s b/ft_list_size.s
new file mode 100644
index 0000000..c37de61
--- /dev/null
+++ b/ft_list_size.s
@@ -0,0 +1,25 @@
+# **************************************************************************** #
+# #
+# ::: :::::::: #
+# ft_list_size.s :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2019/11/22 20:59:52 by cacharle #+# #+# #
+# Updated: 2019/11/22 21:17:54 by cacharle ### ########.fr #
+# #
+# **************************************************************************** #
+
+.globl _ft_list_size
+
+# int ft_list_size(t_list *begin_list);
+_ft_list_size:
+ xor eax, eax
+ FT_LIST_SIZE_LOOP:
+ cmp rdi, 0
+ je FT_LIST_SIZE_END
+ inc eax
+ mov rdi, [rdi + 8]
+ jmp FT_LIST_SIZE_LOOP
+ FT_LIST_SIZE_END
+ ret
diff --git a/ft_list_sort.s b/ft_list_sort.s
new file mode 100644
index 0000000..dc16183
--- /dev/null
+++ b/ft_list_sort.s
@@ -0,0 +1,36 @@
+# **************************************************************************** #
+# #
+# ::: :::::::: #
+# ft_list_sort.s :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2019/11/22 21:03:52 by cacharle #+# #+# #
+# Updated: 2019/11/22 21:17:36 by cacharle ### ########.fr #
+# #
+# **************************************************************************** #
+
+.globl _ft_list_sort
+
+# void ft_list_sort(t_list **begin_list, int (*cmp)());
+_ft_list_sort:
+ push rbp
+ mov rbp, rsp
+
+ call _ft_list_size
+ cmp eax, 2
+ jl FT_LIST_SORT_END
+
+ # split in half
+ # _ft_list_sort both half
+ # merge_sorted
+
+
+ FT_LIST_SORT_END:
+ pop rbp
+ ret
+
+
+merge_sorted:
+
+
diff --git a/ft_read.s b/ft_read.s
index e8b0d2e..e249078 100644
--- a/ft_read.s
+++ b/ft_read.s
@@ -6,12 +6,13 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/11/22 03:04:44 by cacharle #+# #+# #
-# Updated: 2019/11/22 03:04:45 by cacharle ### ########.fr #
+# Updated: 2019/11/22 21:19:13 by cacharle ### ########.fr #
# #
# **************************************************************************** #
.globl _ft_read
+# int ft_read(int, void*, size_t);
_ft_read:
mov rax, 0x2000003
syscall
diff --git a/ft_strcmp.s b/ft_strcmp.s
index 8dd6e01..e04938a 100644
--- a/ft_strcmp.s
+++ b/ft_strcmp.s
@@ -6,12 +6,13 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/11/22 03:04:38 by cacharle #+# #+# #
-# Updated: 2019/11/22 03:04:39 by cacharle ### ########.fr #
+# Updated: 2019/11/22 21:18:49 by cacharle ### ########.fr #
# #
# **************************************************************************** #
.globl _ft_strcmp
+# int ft_strcmp(const char *s1, const char *s2);
_ft_strcmp:
mov rax, rdi # s1
mov rbx, rsi # s2
diff --git a/ft_strcpy.s b/ft_strcpy.s
index d20476d..820d970 100644
--- a/ft_strcpy.s
+++ b/ft_strcpy.s
@@ -6,12 +6,13 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/11/22 03:04:28 by cacharle #+# #+# #
-# Updated: 2019/11/22 03:16:19 by cacharle ### ########.fr #
+# Updated: 2019/11/22 21:18:38 by cacharle ### ########.fr #
# #
# **************************************************************************** #
.globl _ft_strcpy
+# char *ft_strcpy(char *dst, const char *src);
_ft_strcpy:
mov rax, rdi # dst
mov rbx, rsi # src
diff --git a/ft_strdup.s b/ft_strdup.s
index b174239..d96ad3b 100644
--- a/ft_strdup.s
+++ b/ft_strdup.s
@@ -6,12 +6,13 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/11/22 03:04:32 by cacharle #+# #+# #
-# Updated: 2019/11/22 03:16:37 by cacharle ### ########.fr #
+# Updated: 2019/11/22 21:19:29 by cacharle ### ########.fr #
# #
# **************************************************************************** #
.globl _ft_strdup
+# char *ft_strdup(const char*);
_ft_strdup:
push rbp
mov rbp, rsp
diff --git a/ft_strlen.s b/ft_strlen.s
index 365fa80..2965ada 100644
--- a/ft_strlen.s
+++ b/ft_strlen.s
@@ -6,13 +6,14 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/11/22 03:04:20 by cacharle #+# #+# #
-# Updated: 2019/11/22 03:04:22 by cacharle ### ########.fr #
+# Updated: 2019/11/22 21:18:30 by cacharle ### ########.fr #
# #
# **************************************************************************** #
.globl _ft_strlen
- _ft_strlen:
+# int ft_strlen(char *);
+_ft_strlen:
mov rbx, rdi # str argument
xor rax, rax
FT_STRLEN_LOOP:
diff --git a/ft_write.s b/ft_write.s
index 2e26ccd..7303af0 100644
--- a/ft_write.s
+++ b/ft_write.s
@@ -6,12 +6,13 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/11/22 03:04:47 by cacharle #+# #+# #
-# Updated: 2019/11/22 03:04:48 by cacharle ### ########.fr #
+# Updated: 2019/11/22 21:19:02 by cacharle ### ########.fr #
# #
# **************************************************************************** #
.globl _ft_write
+# int ft_write(int, const void*, size_t);
_ft_write:
mov rax, 0x2000004
syscall
diff --git a/main.c b/main.c
index dcde391..0bf3354 100644
--- a/main.c
+++ b/main.c
@@ -6,13 +6,19 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/22 02:02:24 by cacharle #+# #+# */
-/* Updated: 2019/11/22 05:18:39 by cacharle ### ########.fr */
+/* Updated: 2019/11/22 21:00:30 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
+typedef struct s_list
+{
+ void *data;
+ struct s_list *next;
+} t_list;
+
int ft_strlen(char *);
char *ft_strcpy(char *dst, const char *src);
int ft_strcmp(const char *s1, const char *s2);
@@ -20,6 +26,10 @@ int ft_write(int, const void*, size_t);
int ft_read(int, void*, size_t);
char *ft_strdup(const char*);
int ft_atoi_base(const char*, const char*);
+int check_base(const char*);
+
+void ft_list_push_front(t_list **begin_list, void *data);
+int ft_list_size(t_list *begin_list);
int main()
{
@@ -31,7 +41,7 @@ int main()
/* printf("%d\n", ft_strlen(a)); */
/* printf("%d\n", ft_strlen(b)); */
/* printf("%d\n", ft_strlen("bonjour")); */
- /* */
+
/* char c[32] = "bon"; */
/* char *d = "bonjourasdfasdf"; */
/* printf("%s\n", ft_strcpy(c, d)); */
@@ -53,7 +63,9 @@ int main()
/* printf("%s\n", h); */
/* free(h); */
- printf("%d\n", ft_atoi_base(" \t\v\r \n 101h", "01"));
+ /* printf("%d\n", check_base("01")); */
+
+ printf("%d\n", ft_atoi_base(" \t\v\r \n 1012h", "01"));
return 0;
}