Author Topic: Accept input from user  (Read 17308 times)

Offline AdityaKhursale

  • New Member
  • Posts: 1
Accept input from user
« on: March 30, 2014, 07:19:05 AM »
How input gets stored in nasm when accepted it from user ?

Example:

mov eax,3
mov ebx,2
mov ecx,num1
mov edx,3
int 80h
& suppose I have accepted 12 then what will be stored in [num1],[num1 + 1] & in [num1 + 2] ?


 

Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: Accept input from user
« Reply #1 on: March 30, 2014, 07:28:48 AM »
How input gets stored in nasm when accepted it from user ?

This is not "nasm" problem, case.

Well, it seems you don't understand, what are you talking about.

Learn the interrupt, system function that you are using.

EDIT:


Quote
I have accepted 12 then what will be stored in [num1],[num1 + 1] & in [num1 + 2] ?

If you have accepted 12 digits (12 entered, keyboard key press), then,
[num1] should be the first digit that you entered,
[num2] should be the second digit that you entered.

If you want to input 12 numbers, you have to have a separate place for each number input.

It think, you will not, be able to input N numbers with a single system call, that would not be very smart.
You want to input N numbers? - Then call "single system call" N times and have those numbers (convert them, store them in buffer or else do what you like).

And, by the way, we don't input numbers!
We input and send keyboard strokes that are stored into buffer.
Input is usually terminated by ENTER or by buffer len.



Call 12x times, like this:
Quote
mov eax...
mov ebx...
mov ecx,num1
mov edx...
int 80h

mov eax...
mov ebx...
mov ecx,num2
mov edx...
int 80h

...

So, if you want to get a number from the input, you have to convert buffer, each digit, to a number.

EDIT:


mov eax...
mov ebx...
mov ecx,buffer
mov edx...
int 80h

If you input "HeLLo world",
after the input,
buffer content should be:
[buffer+0] = 'H'
[buffer+1] = 'e'
[buffer+2] = 'L'
[buffer+3] = 'L'
...

and so on.
« Last Edit: March 30, 2014, 08:27:09 AM by encryptor256 »
Encryptor256's Investigation \ Research Department.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Accept input from user
« Reply #2 on: March 30, 2014, 09:05:33 AM »
Pay no attention to the Windows guys! (just jokin', encryptor256)
Quote
Well, it seems you don't understand, what are you talking about.
Of course not! That's why he's askin'!

You should find, in [num1] the character '1' (not the number 1 - the ascii code - 31h or 49 decimal), in [num1 + 1], the character '2', and in [num1 + 2], a linefeed (0Ah or 10 decimal). This assumes that the user has typed '1', '2', "enter".

If the pesky user types "12345" (enter), you'll have "123" in [num1] - it won't overflow - and "34(linefeed)" remains in the "keyboard buffer" waiting to screw up our next sys_read, or it will appear on the bash prompt if we sys_exit first. This is not good! We can discuss how to "flush the buffer"...

This "example code" section is probably not the best place to discus this kind of question. The "programming with Nasm" section is probably better. (doesn't really make too much difference) I may try to move the topic. Or maybe I'll leave well enough alone and not risk screwing things up further. I suppose if I provided a working example, it would be in the right place. I'll think about it. Stay tuned.

Oh, yeah. "Welcome to the forum!" :)

Best,
Frank