flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Chewy509 08 May 2008, 00:20
getch: do a 1 byte read (sys_read, eax = 3) with the file handle 00h...
(Default handles in Linux: STDIN = 00h STDOUT = 01h STDERR = 02h ) Here is the asm (for AMD64): Code: mov rax, 03; // Sys_read mov rbx, 00h; // Handle mov rcx, buffer; // Location to store your input mov rdx, 1; // 1 byte; syscall test rax, rax jz .@f movzx rax, byte [buffer] jmp forward: .@@: xor rax, rax dec rax forward: ;; rax contains your character, or -1 if EOF. kbhit: There is no native solution, but the following C version does what you are after: Code: /* kbhit.h */ #include <sys/select.h> int kbhit(void) { struct timeval tv; fd_set read_fd; tv.tv_sec=0; tv.tv_usec=0; FD_ZERO(&read_fd); FD_SET(0,&read_fd); if(select(1, &read_fd, NULL, NULL, &tv) == -1) return 0; if(FD_ISSET(0,&read_fd)) return 1; return 0; } Then you can include the above "kbhit.h" and use the kbhit() function. For example, Code: #include <stdio.h> #include "kbhit.h" int main() { printf("hello\n"); printf("Press any key to continue..\n"); while(!kbhit()); printf("bye bye\n"); return 0; } I'll let you do the translation into asm... (or use gcc to output the resultant asm).[/code] |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.