I'm trying to modify some sample codes to get a handle on ASM.
I don't have a problem with output, but I can't seem to get input working correctly.
How would I for example input a string from the user?
I've seen ReadString mentioned here and there but can't get any good documentation on how to implement this procedure that makes sense to a complete novice.
Also how could I input some integers? I want to have an array of integers that the user can input into but I don't even have a clue what command you use in ASM for inputting an integer.
sharpnova.
Quote
Also how could I input some integers? I want to have an array of integers that the user can input into but I don't even have a clue what command you use in ASM for inputting an integer.
Specifically, you don't. You would input characters that represent integers. Once you get the characters into a buffer or something, you process them into integers. It is easy to convert 37h to 7, for example.
Are you writing a console app? The answer to your first question would depend upon your answer to my question. If it is a console app, Hutch has already done the work for you. wait_key, for example, quickly comes to my mind but there is more than one method in his library. For a windows app, there is GetTextInput (I think).
Anyway, take a look at what he has in there. There is no sense in re-inventing the wheel.
Paul
Hello,
Quote
How would I for example input a string from the user?
For this ,use a window and a dialog box with an edit control.
sharpnova,
The ReadString procedure most frequently mentioned here is from the Irvine32 library and it is designed to read a string from the console. If you have that library then you should have the source for it, and a description of how to use it should be in the comment header just above the procedure definition. If you do not have that library then there are multiple alternatives, but without knowing more about what you're trying to do and what libraries and code you have available (MASM32, GeneSys, Irvine32, etc), it's hard to know what to suggest.
Hi sharpnova,
There are functions provided with masm32.lib to receive keyboard input and convert NULL terminated strings to DWORD.
Here is a quick example :
include InputTest.inc
BUFFER_LENGTH = 100
BUFFER_LENGTH2 = 16
.data
message1 db 'Type a string :',13,10,0
message2 db 'Type an integer, x = ',13,10,0
format1 db 'String = %s',13,10,'2 * x + 1 = %d',13,10,0
.data?
string db BUFFER_LENGTH dup(?)
integer db BUFFER_LENGTH2 dup(?)
buffer db 256 dup(?)
.code
start:
invoke StdOut,ADDR message1 ; output a NULL terminated string
invoke StdIn,ADDR string,BUFFER_LENGTH ; read keyboard input from console
invoke StdOut,ADDR message2
invoke StdIn,ADDR integer,BUFFER_LENGTH2
; StdIn returns the lenght of the input text
mov BYTE PTR [integer+eax-2],0 ; remove the CR+LF terminator
invoke atodw,ADDR integer ; convert the decimal string to dword
shl eax,1 ; multiply by 2
inc eax ; add 1
invoke wsprintf,ADDR buffer,ADDR format1,ADDR string,eax
invoke StdOut,ADDR buffer
invoke ExitProcess,0
END start
[attachment deleted by admin]