Readin single character from keybard (linux/nasm)

Thread Solved

Join Date: Dec 2008
Posts: 25
Reputation: jt_murphree is an unknown quantity at this point 
Solved Threads: 1
jt_murphree's Avatar
jt_murphree jt_murphree is offline Offline
Light Poster

Readin single character from keybard (linux/nasm)

 
0
  #1
Dec 14th, 2008
I am attempting to write assembly code for linux using nasm. I have an include file containing io functions that was originally written for windows using masm and I am trying to convert it. I have on procedure that I am having problems with. The procedure is supposed to recieve on character of input from the keybard. The windows version only allow you to input one character. Once a key is pressed the program continues with out requireing you to press the enter key. The version I have modified does not do this. It requires you to press enter and when you do it acts as if it is reading two characters, I am assuming this is because it is reading the enter key as well as the character typed. This casues the program to exit and I get two prompts after it ends, as if I was at the prompt and just pressed enter. I am including the code below. Can anyone tell me how to remedy this?

  1. ;********************procedure to get char from keyboard*******************
  2. ;Given : variable to store to in esi
  3. ;Process : make linux system call to get character from keyboard.
  4. ;Returns : nothing
  5. ;Author : Jason T. Murphree
  6. ;************************************************************************
  7. getChar:
  8. pushad ;save registers
  9. pushfd ;save flags
  10.  
  11. mov eax, 3 ;sys_read(3)
  12. mov ebx, 0 ;stdin (0)
  13. mov ecx, esi ;string to store to
  14. mov edx, 1 ;number of bytes to read
  15. int 0x80 ;interupt for linux
  16.  
  17.  
  18.  
  19. popfd ;restore flags
  20. popad ;restore registers
  21. ret ;return to calling procedure
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 129
Reputation: Evenbit is on a distinguished road 
Solved Threads: 4
Evenbit's Avatar
Evenbit Evenbit is offline Offline
Junior Poster

Re: Readin single character from keybard (linux/nasm)

 
0
  #2
Dec 20th, 2008
You will need to tweak 'termios' to get non-buffered input to work. Read this thread for code and discussion of the issue:

http://sourceforge.net/mailarchive/f...la-stdlib-talk

Nathan.
while (CPU is present) {some assembly required}
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 25
Reputation: jt_murphree is an unknown quantity at this point 
Solved Threads: 1
jt_murphree's Avatar
jt_murphree jt_murphree is offline Offline
Light Poster

Re: Readin single character from keybard (linux/nasm)

 
0
  #3
Dec 22nd, 2008
Thanks, that is exactly what I needed
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC