Wait for keypress Assembly NASM, Linux -


i'm working on hello world in assembly x86-64.

i have managed create 1 finishes when enter key pressed, have finish when key pressed.

this code waiting enter key:

mov rax, 0 mov rdi, 0 mov rdx, 1 syscall 

i can't use int xh or that. syscalls.

thanks!

i've answered a similar question before, , gave c code work directly system calls wanted.

here's translation of code nasm, slight changes reflect you're checking key pressed, not specific key:

fwait:     ; fetch current terminal settings     mov rax, 16    ; __nr_ioctl     mov rdi, 0     ; fd: stdin     mov rsi, 21505 ; cmd: tcgets     mov rdx, orig  ; arg: buffer, orig     syscall      ; again, time 'new' buffer     mov rax, 16     mov rdi, 0     mov rsi, 21505     mov rdx, new     syscall      ; change settings     , dword [new+0], -1516    ; ~(ignbrk | brkint | parmrk | istrip | inlcr | igncr | icrnl | ixon)     , dword [new+4], -2       ; ~opost     , dword [new+12], -32844  ; ~(echo | echonl | icanon | isig | iexten)     , dword [new+8], -305     ; ~(csize | parenb)     or  dword [new+8], 48        ; cs8      ; set settings (with ioctl again)     mov rax, 16    ; __nr_ioctl     mov rdi, 0     ; fd: stdin     mov rsi, 21506 ; cmd: tcsets     mov rdx, new   ; arg: buffer, new     syscall      ; read character     mov rax, 0     ; __nr_read     mov rdi, 0     ; fd: stdin     mov rsi, char  ; buf: temporary buffer, char     mov rdx, 1     ; count: length of buffer, 1     syscall      ; reset settings (with ioctl again)     mov rax, 16    ; __nr_ioctl     mov rdi, 0     ; fd: stdin     mov rsi, 21506 ; cmd: tcsets     mov rdx, orig  ; arg: buffer, orig     syscall      ret 

the basic idea have edit terminal settings, read character, , reset settings.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -