-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_write.s
More file actions
29 lines (26 loc) · 1.45 KB
/
Copy pathft_write.s
File metadata and controls
29 lines (26 loc) · 1.45 KB
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
; **************************************************************************** #
; #
; :::::::: #
; ft_write.s :+: :+: #
; +:+ #
; By: rvan-sch <[email protected]> +#+ #
; +#+ #
; Created: 2020/11/08 19:06:28 by rvan-sch #+# #+# #
; Updated: 2020/11/08 19:06:28 by rvan-sch ######## odam.nl #
; #
; **************************************************************************** #
global _ft_write ; ssize_t ft_write(int fd_rdi, const void *buf_rsi, size_t nbyte_rdx)
extern ___error
_ft_write:
mov rax, 0x2000004 ; system call for write on MacOS
syscall ; do the system call
jc .error ; if an error happened, the carry flag is set
ret
.error:
push rax ; save return value for later
call ___error ; retrieve the error code
mov rdi, rax ; point rdi to errno
pop rax ; retrieve previous value of rax
mov [rdi], rax ; value is now in the mem of errno
mov rax, -1 ; our write now returns -1 just like the original function
ret