Added commentary
This commit is contained in:
9
Makefile
9
Makefile
@@ -6,7 +6,7 @@
|
|||||||
# By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ #
|
# By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/03/15 14:16:21 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
|
ARFLAG = rc
|
||||||
|
|
||||||
.s.o :
|
.s.o :
|
||||||
${CC} $< -o ${<:.s=.o} ${FLAGS}
|
@printf "\e[1;32m[compiling {"$(CC)"}...]\e[1;00m "$<"\n"
|
||||||
|
@${CC} $< -o ${<:.s=.o} ${FLAGS}
|
||||||
|
|
||||||
all: ${NAME}
|
all: ${NAME}
|
||||||
|
|
||||||
${NAME}: ${OBJS}
|
${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:
|
clean:
|
||||||
rm -f ${OBJS}
|
rm -f ${OBJS}
|
||||||
|
|||||||
34
ft_strcmp.s
34
ft_strcmp.s
@@ -1,27 +1,27 @@
|
|||||||
global ft_strcmp
|
global ft_strcmp
|
||||||
|
|
||||||
ft_strcmp:
|
ft_strcmp:
|
||||||
xor r8, r8
|
xor r8, r8 ; r8 = 0
|
||||||
xor rax, rax
|
xor rax, rax ; rax = 0
|
||||||
|
|
||||||
.count:
|
.count:
|
||||||
mov al, BYTE [rdi + r8]
|
mov al, BYTE [rdi + r8] ; al = s1[r8]
|
||||||
mov dl, BYTE [rsi + r8]
|
mov dl, BYTE [rsi + r8]; dl = s2[r8]
|
||||||
test al, al
|
test al, al ; if (al == 0)
|
||||||
jz .end
|
jz .end ; goto end
|
||||||
test dl, dl
|
test dl, dl ; if (dl == 0)
|
||||||
jz .end
|
jz .end ; goto end
|
||||||
cmp al, dl
|
cmp al, dl ; compare al and dl
|
||||||
jne .end
|
jne .end ; if not equal, goto end
|
||||||
inc r8
|
inc r8 ; r8++
|
||||||
jmp .count
|
jmp .count ; repeat
|
||||||
|
|
||||||
.end:
|
.end:
|
||||||
sub al, dl
|
sub al, dl ; take diff between al and dl
|
||||||
js .neg
|
js .neg
|
||||||
ret
|
ret ; return it
|
||||||
|
|
||||||
.neg:
|
.neg:
|
||||||
neg al
|
neg al ; al = -al;
|
||||||
neg rax
|
neg rax ; al is the first 8 bit of rax, so reverse it
|
||||||
ret
|
ret ; return it
|
||||||
@@ -14,9 +14,9 @@ ft_strdup:
|
|||||||
je .end
|
je .end
|
||||||
pop rsi ; we take the value we saved earlier
|
pop rsi ; we take the value we saved earlier
|
||||||
mov rdi, rax ; move the result of malloc into rdi (override strlen result)
|
mov rdi, rax ; move the result of malloc into rdi (override strlen result)
|
||||||
call ft_strcpy
|
call ft_strcpy ; copy the string
|
||||||
ret
|
ret ; result is put into rax, return it
|
||||||
|
|
||||||
.end:
|
.end:
|
||||||
pop rsi
|
pop rsi ; remove rsi from the stack
|
||||||
ret
|
ret ; return
|
||||||
13
ft_strlen.s
13
ft_strlen.s
@@ -1,13 +1,12 @@
|
|||||||
global ft_strlen
|
global ft_strlen
|
||||||
|
|
||||||
ft_strlen:
|
ft_strlen:
|
||||||
xor rax, rax
|
xor rax, rax ; rax = 0;
|
||||||
|
|
||||||
.cmp_char:
|
.cmp_char:
|
||||||
cmp byte [rdi + rax], 0
|
cmp byte [rdi + rax], 0 ; if (str[rax] == 0)
|
||||||
je .end
|
je .end ; goto end
|
||||||
inc rax
|
inc rax ; rax++;
|
||||||
jmp .cmp_char
|
jmp .cmp_char ; repeat
|
||||||
|
|
||||||
.end:
|
.end:
|
||||||
ret
|
ret ; return it
|
||||||
@@ -2,16 +2,16 @@ global ft_write
|
|||||||
extern __errno_location
|
extern __errno_location
|
||||||
|
|
||||||
ft_write:
|
ft_write:
|
||||||
cmp rsi, 0
|
cmp rsi, 0 ; if buffer is null
|
||||||
je .bad_buff
|
je .bad_buff ; goto bad_buff
|
||||||
mov eax, 0x1 ; put the syscall number of write
|
mov eax, 0x1 ; put the syscall number of write
|
||||||
syscall
|
syscall ; call write
|
||||||
test rax, rax ; test if the syscall failed
|
test rax, rax ; test if the syscall failed
|
||||||
js .error
|
js .error
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.bad_buff:
|
.bad_buff:
|
||||||
mov rdx, 22
|
mov rdx, 22 ; put the corresponding errno code
|
||||||
call __errno_location wrt ..plt
|
call __errno_location wrt ..plt
|
||||||
mov [rax], rdx
|
mov [rax], rdx
|
||||||
mov rax, -1
|
mov rax, -1
|
||||||
|
|||||||
Reference in New Issue
Block a user