Added tester and commentary to asm files
This commit is contained in:
20
ft_read.s
20
ft_read.s
@@ -2,16 +2,16 @@ global ft_read
|
||||
extern __errno_location
|
||||
|
||||
ft_read:
|
||||
mov eax, 0
|
||||
mov eax, 0 ; move the syscall code of write (0) into eax (syscall register)
|
||||
syscall
|
||||
test rax, rax
|
||||
js .error
|
||||
ret
|
||||
test rax, rax ; check if the syscall failed
|
||||
js .error ; if the syscall failed, jump at .error
|
||||
ret ; else return
|
||||
|
||||
.error:
|
||||
mov rdx, rax
|
||||
call __errno_location wrt ..plt
|
||||
neg rdx
|
||||
mov [rax], rdx
|
||||
mov rax, -1
|
||||
ret
|
||||
mov rdx, rax ; save rax (return value) into rdx as a temp value
|
||||
call __errno_location wrt ..plt ; call errno_location (put errno pointer into rax) | wrt ..plt means the address of the function will be defined at runtime (needed for libc)
|
||||
neg rdx ; invert the return value
|
||||
mov [rax], rdx ; *errno_value = rdx
|
||||
mov rax, -1 ; set the return value to -1
|
||||
ret ; return
|
||||
Reference in New Issue
Block a user