echo then close connection

This commit is contained in:
root 2025-05-11 08:22:07 +00:00
parent 60e9bcf95c
commit d54596514c
2 changed files with 83 additions and 7 deletions

36
readline.s Normal file
View file

@ -0,0 +1,36 @@
; Returns length in rax
; Errors (in rax):
; -1024 - line too long
; other negative - error 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
jge readline__overflow
mov r11b, [rsi + r10]
add r10, 1
cmp r11b, 0x0a ; '\n'
jne readline__scan
readline__return:
mov rax, r10
ret
readline__overflow:
mov rax, -1024
ret