News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

commandline I/O ?

Started by A_B, February 14, 2010, 07:02:24 AM

Previous topic - Next topic

A_B

Hi,

Simple question (I hope); What is the best (simplest, fastest) way to get input through a command line, and to output to the command line.
For example, I have the euclidean algorithm an I want the user to provide  numbers which are then stored in 2 registers. After the program is done, the gcd is in a register and has to be displayed on the command line.

I can find how to display strings using StdOut etc. but they seem not very compatible with printing numbers stored in the registers.

Thanks
Alex

donkey

input and output to the console (its the right name for the commandline) is always going to be strings, you will have to convert the numbers to strings then use stdout. There is probably a function in MASM32 for that.

To get information from the command line use

invoke GetCommandLine

It will return the pointer to the command line in EAX, you will have to parse it for the parameters or I believe there might be something in MASM32 that will do that for you too.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

jj2007

Is this what you want?

include \masm32\include\masm32rt.inc

.data?
MyBuffer db 1024 dup(?)

.code
start:

invoke GetCL, 1, offset MyBuffer ; 1=first argument
.if eax==1 ; 1=valid argument found
print offset MyBuffer, " was the command line", 13, 10
.else
print "No argument found", 13, 10
.endif
mov esi, input("Give me some text: ")
print esi, " was the extra text", 13, 10
inkey "Press any key"
exit


end start

A_B

thanks, that does the trick.

Alex