flat assembler
Message board for the users of flat assembler.

Index > Linux > how do you flush the keyboard after input?

Author
Thread Post new topic Reply to topic
MajorDill



Joined: 01 Nov 2010
Posts: 22
MajorDill 15 Feb 2015, 21:10
So here is some code to get input from the keyboard. It works okay until you enter more
characters than it is expecting (in this case 10). The program exits to linux and any extra input is place after the prompt with the ENTER key. Is there some way to flush out the extra stuff after grabbing the 10?

Code:
format ELF executable

entry _start
  prompt     db  '>'
  in_str     rb  10

_start:
   mov   eax,4           ;display prompt
   mov   ebx,1
   mov   ecx,prompt
   mov   edx,1
   int   0x80

   mov   eax,3           ;get input from keyboard
   mov   ebx,0
   mov   ecx,in_str
   mov   edx,10
   int   0x80

   mov   eax,4           ;display input
   mov   ebx,1
   mov   ecx,in_str
   mov   edx,10
   int   0x80

   mov   eax,1           ;exit linux
   xor   ebx,ebx
   int   0x80
    
Post 15 Feb 2015, 21:10
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 15 Feb 2015, 21:25
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 17:55; edited 1 time in total
Post 15 Feb 2015, 21:25
View user's profile Send private message Reply with quote
gens



Joined: 18 Feb 2013
Posts: 161
gens 15 Feb 2015, 22:56
i don't know of a direct way, so

eax returns the number of bytes read, so just read until you get less then you asked for
Post 15 Feb 2015, 22:56
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 16 Feb 2015, 02:17
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 17:55; edited 2 times in total
Post 16 Feb 2015, 02:17
View user's profile Send private message Reply with quote
gens



Joined: 18 Feb 2013
Posts: 161
gens 16 Feb 2015, 12:48
HaHaAnonymous wrote:
Quote:

eax returns the number of bytes read, so just read until you get less then you asked for

The same thing will happen if it what was returned exceeded the buffer size. I think he should increase the size of the buffer for that.

if you request 10 bytes and there is 100 in the stdin buffer, you will get 10 bytes and a 10 in eax
Post 16 Feb 2015, 12:48
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 16 Feb 2015, 23:08
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 17:55; edited 1 time in total
Post 16 Feb 2015, 23:08
View user's profile Send private message Reply with quote
Gunner



Joined: 28 Jul 2003
Posts: 17
Location: In my head
Gunner 17 Feb 2015, 00:57
Here is a tutorial on how to deal with this, it is with NASM but easy enough to convert www.dreamincode.net/forums/topic/286248-nasm-linux-terminal-inputoutput-wint-80h/

_________________
~Rob (Gunner)
Forum Spam List Checker
Window Error Lookup Tool
and MORE!
Post 17 Feb 2015, 00:57
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 670
system error 17 Feb 2015, 07:02
I am not sure if this is related, but EOL character eats up 1 byte from the total. For a reserved 10 chars, only 9 bytes are good. The other 1 is goes to EOL (0ah, enter key). I always reserve one byte for EOL.
Post 17 Feb 2015, 07:02
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.