aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile17
-rw-r--r--ft_atoi_base.s14
-rw-r--r--ft_read.s4
-rw-r--r--ft_strcmp.s4
-rw-r--r--ft_strcpy.s4
-rw-r--r--ft_strdup.s16
-rw-r--r--ft_strlen.s4
-rw-r--r--ft_write.s4
-rw-r--r--main.c5
10 files changed, 41 insertions, 32 deletions
diff --git a/.gitignore b/.gitignore
index 0291a3f..90fed4c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ test.s
test.c
t.c
t.s
+runtest
diff --git a/Makefile b/Makefile
index f1aa92d..7a3282e 100644
--- a/Makefile
+++ b/Makefile
@@ -12,26 +12,33 @@
RM = rm -f
LIB = ar rcs
+UNAME = $(shell uname)
CC = gcc
-CCFLAGS = -Wall -Wextra -fomit-frame-pointer
+CCFLAGS = -Wall -Wextra -fomit-frame-pointer -fPIC
NASM = nasm
-NASMFLAGS = -f macho64
+ifeq ($(UNAME),Linux)
+ NASMFLAGS = -f elf64
+else
+ NASMFLAGS = -f macho64
+endif
NAME = libasm.a
ASMSRC = ft_strlen.s ft_strcpy.s ft_strcmp.s ft_write.s ft_read.s \
- ft_strdup.s ft_atoi_base.s ft_list_push_front.s \
- ft_list_size.s ft_list_sort.s ft_list_remove_if.s
+ ft_strdup.s ft_atoi_base.s #ft_list_push_front.s \
+ # ft_list_size.s ft_list_sort.s ft_list_remove_if.s
ASMOBJ = $(ASMSRC:.s=.o)
+TESTNAME = runtest
+
all: $(NAME)
$(NAME): $(ASMOBJ)
$(LIB) $(NAME) $(ASMOBJ)
test: all
- $(CC) main.c $(NAME)
+ $(CC) main.c $(NAME) -o $(TESTNAME)
%.o: %.s
$(NASM) $(NASMFLAGS) -o $@ $<
diff --git a/ft_atoi_base.s b/ft_atoi_base.s
index 663b399..5a8d4c1 100644
--- a/ft_atoi_base.s
+++ b/ft_atoi_base.s
@@ -19,7 +19,7 @@
; 2. pass param with regs rdi, rsi, rdx, rcx, r8, r9
; if there is more pass them onto the stack in reverse order
; 3. use call
-; 4. restore stack state by removing passed on the stack param
+; 4. restore stack state by removing passed on the stack param
; 5. return value of callee in rax
; 6. restore the caller-saved register and saved passed params
; We can assume that no other register has been altered.
@@ -38,12 +38,12 @@
; 6. use ret
-extern _ft_strlen
+extern ft_strlen
-global _ft_atoi_base
+global ft_atoi_base
; int ft_atoi_base(const char *str, const char *base);
-_ft_atoi_base:
+ft_atoi_base:
; ===prolog===
; long int nb (8)
; int radix (4)
@@ -95,9 +95,9 @@ FT_ATOI_BASE_SIGN_LOOP:
; base radix
push rdi
mov rdi, rsi
- call _ft_strlen
+ call ft_strlen
pop rdi
- mov dword [rsp + 8], eax
+ mov dword [rsp + 8], eax
; main loop
FT_ATOI_BASE_LOOP:
@@ -163,7 +163,7 @@ _check_base:
mov dword [rsp], 0
; check for empty or size 1 base
push rdi
- call _ft_strlen
+ call ft_strlen
pop rdi
cmp rax, 2
jl CHECK_BASE_FALSE
diff --git a/ft_read.s b/ft_read.s
index 00718e8..14824f5 100644
--- a/ft_read.s
+++ b/ft_read.s
@@ -10,10 +10,10 @@
; ;
; **************************************************************************** ;
-global _ft_read
+global ft_read
; int ft_read(int, void*, size_t);
-_ft_read:
+ft_read:
mov rax, 0x2000003
syscall
ret
diff --git a/ft_strcmp.s b/ft_strcmp.s
index 7704aa5..03e8d9e 100644
--- a/ft_strcmp.s
+++ b/ft_strcmp.s
@@ -10,10 +10,10 @@
; ;
; **************************************************************************** ;
-global _ft_strcmp
+global ft_strcmp
; int ft_strcmp(const char *s1, const char *s2);
-_ft_strcmp:
+ft_strcmp:
push r12
push r13
push rcx
diff --git a/ft_strcpy.s b/ft_strcpy.s
index 3789283..a1aa4a8 100644
--- a/ft_strcpy.s
+++ b/ft_strcpy.s
@@ -10,10 +10,10 @@
; ;
; **************************************************************************** ;
-global _ft_strcpy
+global ft_strcpy
; char *ft_strcpy(char *dst, const char *src);
-_ft_strcpy:
+ft_strcpy:
push rbx
push rcx
mov rax, rdi ; dst
diff --git a/ft_strdup.s b/ft_strdup.s
index a31f36f..b5420ac 100644
--- a/ft_strdup.s
+++ b/ft_strdup.s
@@ -10,27 +10,27 @@
; ;
; **************************************************************************** ;
-extern _ft_strlen
-extern _ft_strcpy
-extern _malloc
+extern ft_strlen
+extern ft_strcpy
+extern malloc
-global _ft_strdup
+global ft_strdup
; char *ft_strdup(const char *str);
-_ft_strdup:
+ft_strdup:
push rdi ; save rdi because it will be overwrite for malloc
- call _ft_strlen ; rdi is still == str
+ call ft_strlen ; rdi is still == str
inc rax ; len++ for '\0'
mov rdi, rax ; size to malloc
- call _malloc
+ call malloc
cmp rax, 0
je FT_STRDUP_ERROR
pop rsi ; original str as src
mov rdi, rax ; allocated as dest
- call _ft_strcpy
+ call ft_strcpy
ret
FT_STRDUP_ERROR:
pop rdi
diff --git a/ft_strlen.s b/ft_strlen.s
index 2f2dd26..42cba09 100644
--- a/ft_strlen.s
+++ b/ft_strlen.s
@@ -10,10 +10,10 @@
; ;
; **************************************************************************** ;
-global _ft_strlen
+global ft_strlen
; int ft_strlen(char *);
-_ft_strlen:
+ft_strlen:
mov eax, -1
FT_STRLEN_LOOP:
inc eax
diff --git a/ft_write.s b/ft_write.s
index c558ab6..2e3ba00 100644
--- a/ft_write.s
+++ b/ft_write.s
@@ -10,10 +10,10 @@
; ;
; **************************************************************************** ;
-global _ft_write
+global ft_write
; int ft_write(int, const void*, size_t);
-_ft_write:
+ft_write:
mov rax, 0x2000004
syscall
ret
diff --git a/main.c b/main.c
index 333d2a2..70713f7 100644
--- a/main.c
+++ b/main.c
@@ -42,7 +42,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 = "b"; */
/* */
@@ -71,6 +71,7 @@ int main()
/* printf("%d\n", check_base("01")); */
/* printf("%d\n", ft_atoi_base(" \t\n\r\v\f\r 10\t0101001", "01")); */
- printf("_%d_\n", ft_atoi_base(" 755x+", "01234567"));
+ printf("%d\n", ft_atoi_base("01", ""));
+ /* printf("_%d_\n", ft_atoi_base(" 755x+", "01234567")); */
return 0;
}