I have to make a puts function in assembly intel macho64 I would like to understand what and why i didn't print the \n ! in my main.c i'm calling puts twice but i got my text without a \n
I compile with :
nasm -f macho64 ft_puts.s
I make a putstr function to print a string :
%define SYSCALL(nb) 0x2000000 | nb
%define STDOUT 1
%define WRITE 4
section .text
global _ft_putstr
extern _strlen
_ft_putstr:
push rbp
mov rbp , rsp
mov rbx , rdi
cmp rbx , 0x0
je exit
mov rdi , rbx
call _strlen
mov rdx , rax
mov rdi , STDOUT
mov rsi , rbx
mov rax , SYSCALL(WRITE)
syscall
exit:
leave
ret
Then my puts function :
%define SYSCALL(nb) 0x2000000 | nb
%define STDOUT 1
%define WRITE 4
section .rodata
retline db 10
nullstr db "(null)"
section .text
global _ft_puts
extern _ft_putstr
_ft_puts:
push rbp
mov rbp , rsp
mov rbx , rdi
cmp rbx , 0x0
je null
print:
mov rdi , rbx
call _ft_putstr
print_retline:
lea rdi , [rel retline]
call _ft_putstr
exit:
mov rax , '10'
leave
ret
null:
lea rdi , [rel nullstr]
call _ft_putstr
jmp print_retline