; Returns: ; rax - read(2) length ; rdi - if line is complete, line length; ; if line was incomplete, 0; ; if EOF or read(2) returned an error, undefined ; Errors (in rax): ; -1024 - line too long ; other negative - error from read(2) ; 0 - EOF from read(2) ; Arguments: ; rdi - fd ; rsi - buffer ; rdx - max length readline: push rsi push rdx mov rax, SYS_READ syscall pop rdx pop rsi cmp rax, 0 jl return mov r10, 0 readline__scan: cmp r10, rdx jge readline__overflow cmp r10, rax jge readline__incomplete_line mov r11b, [rsi + r10] add r10, 1 cmp r11b, 0x0a ; '\n' jne readline__scan mov rdi, r10 ret readline__incomplete_line: mov rdi, 0 ret readline__overflow: mov rax, -1024 ret