echo server, multiple clients, lines <256 bytes

This commit is contained in:
root 2025-05-13 12:07:03 +00:00
parent d54596514c
commit 29f54ba779
6 changed files with 304 additions and 112 deletions

View file

@ -1,34 +1,41 @@
; Returns length in rax
; 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 rdi
push rsi
push rdx
mov rax, SYS_READ
syscall
pop rdx
pop rsi
pop rdi
cmp rax, 0
jl return
mov r10, 0
readline__scan:
cmp r10, rax
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__return:
mov rax, r10
readline__incomplete_line:
mov rdi, 0
ret
readline__overflow: