Author Topic: 64 bit Keyboard entry using SYSCALL  (Read 8858 times)

Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
64 bit Keyboard entry using SYSCALL
« on: May 08, 2012, 08:50:10 PM »
To make it less burdensome on caller, I've elected to adjust size of buffer and pointer here.  Not sure this is the way I'll leave it, but for now it seems reasonable.

Code: [Select]
; ========================================================================================================
; Read keyboard entry until EOF (return) or overflow ENTRY > RCX.

; ENTRY: RDX = maximum characters
; RSI = Pointer to input buffer

; LEAVE:  If ZR = 0
; RAX = Actuall size of entry
; RDX = Unused space in this buffer
; RSI = Pointer to next position

if ZR = 1
RAX = NULL
All others unchanged

; NOTE: Routine terminates strings with null to be "C" style conformant.
;     25H - 37 Bytes
; ---------------------------------------------------------------------------------------------------------

Keyboard: push rdi
push rcx ; Preserve

xor rax, rax ; SYS_READ = 0
mov rdi, rax ;    STDIN = 0
syscall
dec rax ; Was anything other than carriage return entered
jz .Done ; Bounce if RAX = NULL

; To facilitate entry within a loop I'm going to adjust RDX & RSI accordingly

add rsi, rax ; Point to this entry's carriage return
mov byte [rsi], 0 ; Change to NULL
inc rsi ; Bump to next possible entry position
sub rdx, rax
dec rdx ; Represents room left in this buffer
or rax, rax ; Reset flags

    .Done pop rcx ; Restore registers
pop rdi

  ret