;; getstr.asm ;;
%include "kernel.inc"
global getstr

section .text
getstr: ; < (buffer address), (buffer length)
	push ebp
	mov ebp, esp
	mov edx, [ebp+8]
	xor ecx, ecx
.lp:
	inc ecx
	cmp ecx, [ebp+12]
	jae .quit		; not enough buffer size
	push ecx
	push edx
	kernel 3, 0, edx, 1	; read one character
	pop edx
	pop ecx
	cmp eax, 1		; did we actually get
	jne .quit		;   1 character?
	mov al, [edx]
	cmp al, 10		; we don't need space
	je .quit
	inc edx			; next byte in the buffer
	jmp .lp

.quit:
	mov [edx], byte 0	; add 0 at the end
	mov esp, ebp
	pop ebp
	ret
