-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_read.s
33 lines (33 loc) · 1.54 KB
/
ft_read.s
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
; **************************************************************************** ;
; ;
; ::: :::::::: ;
; ft_read.s :+: :+: :+: ;
; +:+ +:+ +:+ ;
; By: alejandroleon <[email protected] +#+ +:+ +#+ ;
; +#+#+#+#+#+ +#+ ;
; Created: 2020/08/05 06:05:13 by alejandro #+# #+# ;
; Updated: 2020/08/05 06:05:13 by alejandro ### ########.fr ;
; ;
; **************************************************************************** ;
; 1st function parameter: rdi -> fd
; 2nd function parameter: rsi -> buff
; 3rd function parameter: rdx -> n_bytes
;label interactions operands comment
section .text
global _ft_read
extern ___error
_ft_read:
mov rax, 0x2000003 ;Call read.
syscall
jc _syscallerror_return ;If error in syscall, carry flag is set.
ret ;Otherwise we are correctly finished.
_null_return:
mov rax, -1
ret
_syscallerror_return:
push rdi
mov rdi, rax ;rax is Error Code after failed syscall
call ___error ;returns rax as address of errno
mov [rax], rdi ;Sets Error Code in the errno pointer
pop rdi
jmp _null_return