aboutsummaryrefslogtreecommitdiff
path: root/ft_write.s
blob: 01ba5804235b6171d61d1455898966ddb6d9de46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
; **************************************************************************** ;
;                                                                              ;
;                                                         :::      ::::::::    ;
;    ft_write.s                                         :+:      :+:    :+:    ;
;                                                     +:+ +:+         +:+      ;
;    By: cacharle <marvin@42.fr>                    +;+  +:+       +;+         ;
;                                                 +;+;+;+;+;+   +;+            ;
;    Created: 2019/11/22 03:04:47 by cacharle          ;+;    ;+;              ;
;    Updated: 2019/11/22 21:19:02 by cacharle         ;;;   ;;;;;;;;.fr        ;
;                                                                              ;
; **************************************************************************** ;

%ifdef __LINUX__
    %define M_FT_WRITE ft_write
    %define M_ERRNO_LOCATION __errno_location
    %define M_SYSCALL_WRITE 0x1
%else
    %define M_FT_WRITE _ft_write
    %define M_ERRNO_LOCATION ___error
    %define M_SYSCALL_WRITE 0x2000004
%endif

extern M_ERRNO_LOCATION

global M_FT_WRITE

section .text
; int ft_write(int rdi, const void *rsi, size_t rdx);
M_FT_WRITE:
	mov  rax, M_SYSCALL_WRITE
	syscall
%ifdef __LINUX__
    cmp rax, 0
    jl  FT_WRITE_ERROR
%else
    jc  FT_WRITE_ERROR
%endif
	ret
FT_WRITE_ERROR:
%ifdef __LINUX__
    neg  rax
%endif
    push rax
    call M_ERRNO_LOCATION wrt ..plt
    pop  qword [rax]
	mov  rax, -1
	ret