; RIP-relative addressing by default
                  
                  
                  
                  
                  
                  ; compile with:
                  
                  
                  ; nasm -g -f macho64 ft_write.s
                  
                  
                  ; gcc -o a.out ft_write.o main.c
                  
                  
                  
                  
                  
                  
                  
                  
                  ; glibc stuff
                  
                  
                  extern _errno
                  
                  
                  
                  
                  
                  ; code
                  
                  
                  section .text
                  
                  
                  
                  
                  
                  global _ft_write
                  
                  
                  
                  
                  
                  _ft_write:
                  
                  
                    push rsp
                  
                  
                    push rax
                  
                  
                    push rbp
                  
                  
                    push r8
                  
                  
                  
                  
                  
                    sub rsp, 16
                  
                  
                    mov r8, 0x2000004 ; write syscall location
                  
                  
                    lea rax, [r8]
                  
                  
                    syscall
                  
                  
                    test rax, rax
                  
                  
                    jne error
                  
                  
                  
                  
                  
                    xor rax, rax
                  
                  
                    add rsp, 16
                  
                  
                    pop rbp
                  
                  
                    pop rax
                  
                  
                    pop rsppop r8
                  
                  
                    ret
                  
                  
                    
                  
                  
                  error:
                  
                  
                    add rsp, 16
                  
                  
                    call _errno  
                  
                  
                    pop rbp
                  
                  
                    pop rax
                  
                  
                    pop rsp
                  
                  
                    pop r8
                  
                  
                    ret
                  
                  
                
А что, в macOS errno — это функция? Всё у этой вашей Apple не по-человечески!
Обсуждают сегодня