diff --git a/Makefile b/Makefile index c64e674..1979950 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: vvaas +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/03/15 14:16:21 by vvaas #+# #+# # -# Updated: 2024/03/27 17:45:37 by vvaas ### ########.fr # +# Updated: 2024/05/23 14:42:18 by vvaas ### ########.fr # # # #******************************************************************************# @@ -30,12 +30,15 @@ AR = ar ARFLAG = rc .s.o : - ${CC} $< -o ${<:.s=.o} ${FLAGS} + @printf "\e[1;32m[compiling {"$(CC)"}...]\e[1;00m "$<"\n" + @${CC} $< -o ${<:.s=.o} ${FLAGS} all: ${NAME} ${NAME}: ${OBJS} - ${AR} ${ARFLAGS} ${NAME} ${OBJS} + @printf "\e[1;32m[linking {"$(CC)"}...]\e[1;00m "$@"\n" + @${AR} ${ARFLAGS} ${NAME} ${OBJS} + @printf "\e[1;32m[build finished]\e[1;00m\n" clean: rm -f ${OBJS} diff --git a/ft_strcmp.s b/ft_strcmp.s index 1c367d0..08538e6 100644 --- a/ft_strcmp.s +++ b/ft_strcmp.s @@ -1,27 +1,27 @@ global ft_strcmp ft_strcmp: - xor r8, r8 - xor rax, rax + xor r8, r8 ; r8 = 0 + xor rax, rax ; rax = 0 .count: - mov al, BYTE [rdi + r8] - mov dl, BYTE [rsi + r8] - test al, al - jz .end - test dl, dl - jz .end - cmp al, dl - jne .end - inc r8 - jmp .count + mov al, BYTE [rdi + r8] ; al = s1[r8] + mov dl, BYTE [rsi + r8]; dl = s2[r8] + test al, al ; if (al == 0) + jz .end ; goto end + test dl, dl ; if (dl == 0) + jz .end ; goto end + cmp al, dl ; compare al and dl + jne .end ; if not equal, goto end + inc r8 ; r8++ + jmp .count ; repeat .end: - sub al, dl + sub al, dl ; take diff between al and dl js .neg - ret + ret ; return it .neg: - neg al - neg rax - ret \ No newline at end of file + neg al ; al = -al; + neg rax ; al is the first 8 bit of rax, so reverse it + ret ; return it \ No newline at end of file diff --git a/ft_strdup.s b/ft_strdup.s index 114039c..11f96eb 100644 --- a/ft_strdup.s +++ b/ft_strdup.s @@ -14,9 +14,9 @@ ft_strdup: je .end pop rsi ; we take the value we saved earlier mov rdi, rax ; move the result of malloc into rdi (override strlen result) - call ft_strcpy - ret + call ft_strcpy ; copy the string + ret ; result is put into rax, return it .end: - pop rsi - ret \ No newline at end of file + pop rsi ; remove rsi from the stack + ret ; return \ No newline at end of file diff --git a/ft_strlen.s b/ft_strlen.s index b9d2a94..09a39a2 100644 --- a/ft_strlen.s +++ b/ft_strlen.s @@ -1,13 +1,12 @@ global ft_strlen ft_strlen: - xor rax, rax + xor rax, rax ; rax = 0; .cmp_char: - cmp byte [rdi + rax], 0 - je .end - inc rax - jmp .cmp_char - + cmp byte [rdi + rax], 0 ; if (str[rax] == 0) + je .end ; goto end + inc rax ; rax++; + jmp .cmp_char ; repeat .end: - ret \ No newline at end of file + ret ; return it \ No newline at end of file diff --git a/ft_write.s b/ft_write.s index e59b75a..8990255 100644 --- a/ft_write.s +++ b/ft_write.s @@ -2,16 +2,16 @@ global ft_write extern __errno_location ft_write: - cmp rsi, 0 - je .bad_buff + cmp rsi, 0 ; if buffer is null + je .bad_buff ; goto bad_buff mov eax, 0x1 ; put the syscall number of write - syscall + syscall ; call write test rax, rax ; test if the syscall failed js .error ret .bad_buff: - mov rdx, 22 + mov rdx, 22 ; put the corresponding errno code call __errno_location wrt ..plt mov [rax], rdx mov rax, -1