feat(write): adding the write function in asm
This commit is contained in:
parent
d982ec067e
commit
e40d4748cd
1 changed files with 21 additions and 0 deletions
21
src/ft_write.s
Normal file
21
src/ft_write.s
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
segment .note.GNU-stack
|
||||||
|
extern __errno_location
|
||||||
|
|
||||||
|
section .text
|
||||||
|
global ft_write
|
||||||
|
|
||||||
|
ft_write:
|
||||||
|
mov rax, 1 ; syscall 1 is for write
|
||||||
|
syscall ; call the system call write
|
||||||
|
cmp rax, 0 ; check if the return value of syscall
|
||||||
|
jl .error ; jump if the return value is less than 0
|
||||||
|
ret ; return the value of the syscall
|
||||||
|
|
||||||
|
.error:
|
||||||
|
mov rdi, rax ; stock errno value in rdi
|
||||||
|
neg rdi ; errno value in positive (index used by C function)
|
||||||
|
call __errno_location ; rax = &errno
|
||||||
|
mov [rax], edi ; stock the errno return in the address of rax
|
||||||
|
mov rax, -1 ; set the value of rax to -1
|
||||||
|
ret ; return with -1 (and errno value)
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue