flat assembler
Message board for the users of flat assembler.
Index
> Linux > How to read console input? |
Author |
|
scientica 02 Mar 2004, 08:11
Let's see I think these lines should do it: (I can't check right now as I'm in school)
Code: mov eax, 3 ; __NR_read (/linux/include/asm/unistd.h) mov ebx, 0 ; iirc handle 0 is stdin mov ecx, sizeof_input_buffer ; how many chars to read iirc (or if it was max) mov edx, buffer ; the address to our input buffer int 80h I think bazik posted some some nice include with lot's of equates, I'll see if I can find it when I get back home. _________________ ... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself. - Bradley Kuhn |
|||
02 Mar 2004, 08:11 |
|
gorshing 03 Mar 2004, 03:15
Code: format ELF executable entry start section readable writeable str1 db 'enter something: ' str1Len = $-str1 str2 rb 0x100 start: mov eax, 4 mov ebx, 1 mov ecx, str1 mov edx, str1Len int 0x80 mov eax, 3 mov ebx, 0 mov ecx, str2 mov edx, 0x100 int 0x80 mov eax, 4 mov ebx, 1 mov ecx, str2 mov edx, 0x100 int 0x80 mov eax, 1 xor ebx, ebx int 0x80 _________________ gorshing |
|||
03 Mar 2004, 03:15 |
|
maeha 04 Mar 2004, 12:09
Hello scientica, gorshing,
Thank you very much for your kind reply. You are right! But my explanation was not enough due to language ability. I think that the function of ReadConsoleInput(...) in Windows is different from "int 0x80 with mov eax,3" you shown. Becaue, ReadConsoleInput(...) returns to the main when single key touching and sends data into particular structure in INPUT_RECORD buffer. The structure KEY_EVENT_RECORD contains not only AsciiChar but also KeyCode, ScanCode, ControlKeyState, etc. Mouse movement is also detected and its data is sent into MOUSE_EVENT_RECORD. I think that it is possible to implement same function in Linux. But I don't know now. Regards, maeha |
|||
04 Mar 2004, 12:09 |
|
andyz74 15 Sep 2010, 14:13
I have also a problem with reading from keyboard.
I have written this code... Code: format ELF executable entry start segment readable writeable executable start: mov eax,4 mov ebx,1 mov ecx,msg mov edx,msg_size int 80h mov eax,3 mov ebx,1 mov ecx,inp_buf mov edx,100h int 80h mov [inp_buf_size],ax mov eax,4 mov ebx,1 mov ecx,msg2 mov edx,msg2_size int 80h mov eax,4 mov ebx,1 mov ecx,inp_buf xor edx,edx mov edx,inp_buf_size int 80h mov eax,4 mov ebx,1 mov ecx,crlf mov edx,1 int 80h mov eax,1 xor ebx,ebx int 80h segment readable writeable crlf db 0ah msg db 'Input some data: ' msg_size = $-msg inp_buf rb 100h inp_buf_size rw 1 msg2 db 'You entered: ' msg2_size = $-msg2 ...now my keyboard input is stored to the var "input_buf", and the length of the input gets from register ax to var "inp_buf_size". After that, I expected, I can output the text with correct length via syscall 4, but the length of my string is never correct, it is always much too long. I hope, you understand my poor english and my problem and anybody can explain me the error. with kindest reagrds, Andy |
|||
15 Sep 2010, 14:13 |
|
revolution 15 Sep 2010, 14:22
Are you sure that Linux expects inp_buf_size as a word sized value? Maybe you can try using a dword (inp_buf_size rd 1) and storing eax in there.
[edit] Also use mov edx,[inp_buf_size] with the square brackets. |
|||
15 Sep 2010, 14:22 |
|
andyz74 15 Sep 2010, 14:28
Tested it right now as double and with EAX...same error.
/edit: The square brackets!!! Holy shit. now it works..., but why? The other lengths of the variables did work without the brackets? btw: thanks! |
|||
15 Sep 2010, 14:28 |
|
jeff 11 Dec 2010, 23:22
I'm not sure if this is a problem, but some keys create up to 7 characters when pressed. If a key is held down, it repeats and quickly fills up a buffer. Also, it was necessary for me to detect the end of each key so the next key could be decoded. For the console this logic worked OK, but when terminals were used, things got complicated. I'm still somewhat confused by all this and have started moving my programs to Xwindow keyboard handling. Hope this helps.. jeff
|
|||
11 Dec 2010, 23:22 |
|
andyz74 12 Dec 2010, 07:58
A few days ago i wanted to do some inputs (maybe around 8 or 10) with
Quote:
and had also the problem, that all keys were working fine, but when you pressed "enter" for finishing the first input, than "enter" was read several times, so the next few "eax=3/int80h" were already executed and produced empty strings. I think, one day, i will create my own "read-string-procedure", with some construction like Quote:
...but this is in future... |
|||
12 Dec 2010, 07:58 |
|
jeff 12 Dec 2010, 18:12
Hi andyz74, I assume you know about termios setting up for raw or cooked mode of keyboard entry? Another complication is signals, but most people leave signals in the default state and will not have problems. One thing that may be useful is to look at keyecho.asm in asmtools. It echos the output of each key press to the display and is written in assembler.
|
|||
12 Dec 2010, 18:12 |
|
catafest 07 Jan 2012, 12:12
jeff wrote: Hi andyz74, I assume you know about termios setting up for raw or cooked mode of keyboard entry? Another complication is signals, but most people leave signals in the default state and will not have problems. One thing that may be useful is to look at keyecho.asm in asmtools. It echos the output of each key press to the display and is written in assembler. Hi. keyecho.asm is not in Linux FASM ... Also , I thinking the problem is : Code: mov [inp_buf_size],ax and how data is stored ... Maybe is need to use push or pop to save the data and use it. |
|||
07 Jan 2012, 12:12 |
|
Agguro 16 Feb 2012, 21:17
i want to write a program that waits until a user presses a key and then the program continues. In my code i can press a key but i must press enter to continue.
I hope i'm a bit clear with my explanation here, but it's the same as in c++ repeat unti keypressed. I need to use the linux syscall for that (and nope it's no homework, i'm 45 and long way past college) |
|||
16 Feb 2012, 21:17 |
|
Lurker 17 Feb 2012, 02:24
0xA is '\n'
The following code should flassemble fine Code: ;do{read(0,1,&buffer)}while(buffer!='\n');exit(); format ELF executable 3 segment readable executable etiquette: mov eax,3 xor ebx,ebx mov ecx,1 mov edx,buffer int 80h test [buffer],0xA jnz etiquette mov eax,1 xor ebx,ebx int 80h segment writeable readable buffer rb 1 |
|||
17 Feb 2012, 02:24 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.