News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Command Line Arguments

Started by tbohon, March 31, 2015, 07:23:48 AM

Previous topic - Next topic

tbohon

Slowly working my way through some basic MASM32 processes and am currently looking at getting command line arguments.  From my reading here there are 4 different commands/macros which is really confusing :(

I found an example which used cmd$(x) to get the x-th command line argument ... my question is there a way, other than a loop, to get the maximum value of x, i.e., the number of command line arguments present?  In Perl, for example, I can get the number of array entries by looking at the zeroth entry of the array ... and in C I can check the value of argc to get the same value.  I can probably do a loop to count the arguments but am hoping there is already a way that I just haven't found ... yet ...  :biggrin:

Thanks in advance!

Tom

AssemblyChallenge

Hi and welcome!

Try with MASM32's GetCL (Open "masm32\help\masmlib.chm")

You can capture every parameter, store it in a buffer and then process/validate/convert them in order. Ej.

invoke GetCL, 1, addr MyBuffer ; capture first command line parameter, store it on MyBuffer

Regards.

jj2007

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  push CL$(?)            ; question mark returns the number of args
  Print Str$("%i args found:\n", eax)
  pop eax
  For_ ecx=1 To eax
      PrintLine Str$("Arg #%i\t", ecx), CL$(ecx)
  Next
  Inkey "--- OK? ---"
  Exit
end start

OPT_Arg1      This command line has a lot of arguments, including "quoted file names" and single letters such as a b c

Output:
18 args found:
Arg #1  This
Arg #2  command
Arg #3  line
Arg #4  has
Arg #5  a
Arg #6  lot
Arg #7  of
Arg #8  arguments,
Arg #9  including
Arg #10 quoted file names
Arg #11 and
Arg #12 single
Arg #13 letters
Arg #14 such
Arg #15 as
Arg #16 a
Arg #17 b
Arg #18 c


OPT_Arg1 is a RichMasm option that allow to specify a commandline for testing. Argument #0 is the name of the executable (not shown above).

dedndave

that doesn't help him if he's not using MasmBasic

redskull

You can use CommandLineToArgvW(), assuming you separate arguments normally (i.e. spaces).  Don't forget Unicode compliance!  :eusa_naughty:

rrr314159

Quote from: dedndavethat doesn't help him if he's not using MasmBasic

Sure it does, it shows him how much happier and more productive he'll be when he does use MasmBasic ;) - that's helpful isn't it?

... welcome Tom,

personally I don't use it, it's not 64-bit, but it's worth checking out u might like it
I am NaN ;)

dedndave

MasmBasic is great for those who want to learn basic   :P
for those who want to learn assembler - they don't see what's going on in the background
i know Jochen has put a lot of work into it - and i know many of the routines are the fastest around, too   :t

rrr314159

Don't forget the routines are not only fast, but cover a lot of ground ... but basically you're right. If the source code was available it could be an excellent learning tool also, but as it is, perhaps it's better for more advanced users who know (more or less) how it's done under the hood and are happy to let jj do it for them. Best way learn any topic, is re-invent the wheels yourself
I am NaN ;)

jj2007

Quote from: dedndave on March 31, 2015, 03:04:12 PM
MasmBasic is great for those who want to learn basic   :P
for those who want to learn assembler - they don't see what's going on in the background
i know Jochen has put a lot of work into it - and i know many of the routines are the fastest around, too   :t

I thought it was basically a tool to learn assembler... or do you know a better way to learn, for example, SIMD programming without launching Olly? ;)

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  mov eax, 01010101h
  xor ecx, ecx
  .Repeat
      add eax, 01010101h
      movd xmm0, eax
      deb 20, "before pshufd", x:eax, x:xmm0
      pshufd xmm0, xmm0, 3   ; <<<< what does the 3 do??
      deb 20, "after pshufd", ecx, x:xmm0
      inc ecx
  .Until ecx>=1000
  Inkey "ok?"
  Exit
end start


Output:
before pshufd
x:eax           02020202
x:xmm0          00000000 00000000 00000000 02020202

after pshufd
ecx             0
x:xmm0          02020202 02020202 02020202 00000000

before pshufd
x:eax           03030303
x:xmm0          00000000 00000000 00000000 03030303

after pshufd
ecx             1
x:xmm0          03030303 03030303 03030303 00000000

before pshufd
x:eax           04040404
x:xmm0          00000000 00000000 00000000 04040404

after pshufd
ecx             2
x:xmm0          04040404 04040404 04040404 00000000

before pshufd
x:eax           05050505
x:xmm0          00000000 00000000 00000000 05050505

after pshufd
ecx             3
x:xmm0          05050505 05050505 05050505 00000000

before pshufd
x:eax           06060606
x:xmm0          00000000 00000000 00000000 06060606

after pshufd
ecx             4
x:xmm0          06060606 06060606 06060606 00000000

before pshufd
x:eax           07070707
x:xmm0          00000000 00000000 00000000 07070707

after pshufd
ecx             5
x:xmm0          07070707 07070707 07070707 00000000

before pshufd
x:eax           08080808
x:xmm0          00000000 00000000 00000000 08080808

after pshufd
ecx             6
x:xmm0          08080808 08080808 08080808 00000000

before pshufd
x:eax           09090909
x:xmm0          00000000 00000000 00000000 09090909

after pshufd
ecx             7
x:xmm0          09090909 09090909 09090909 00000000

before pshufd
x:eax           0A0A0A0A
x:xmm0          00000000 00000000 00000000 0A0A0A0A

after pshufd
ecx             8
x:xmm0          0A0A0A0A 0A0A0A0A 0A0A0A0A 00000000

before pshufd
x:eax           0B0B0B0B
x:xmm0          00000000 00000000 00000000 0B0B0B0B

after pshufd
ecx             9
x:xmm0          0B0B0B0B 0B0B0B0B 0B0B0B0B 00000000
ok?


@rrr314159: Thanks for the moral support :biggrin:

Gunther

Quote from: jj2007 on March 31, 2015, 05:40:19 PM
I thought it was basically a tool to learn assembler... or do you know a better way to learn, for example, SIMD programming without launching Olly? ;)

Yes, reading a book or manual about the different sets of SIMD instructions. By the way, a bit more understatement wouldn't be so bad.

Gunther
You have to know the facts before you can distort them.

dedndave

that's a discussion for some other forum
this being the campus, let's get back to what the OP wants to know....

the command line routines you are used to (C, Perl - whatever) are largely part of the compiler libraries

windows API provides you with GetCommandLine
https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156%28v=vs.85%29.aspx

msvcrt might provide some help, if you like C programming
i generally parse my own   :P

tbohon

Thanks for all the responses, guys --- and sorry for kicking off a miniature firestorm  :(

I'm going to work on it today while on a 2 hour conference call that, from experience, could probably be replaced by a simple email ... at least they give me time to do something productive!   :eusa_dance:

Vortex

__getmainargs and CommandLineToArgvW :

http://www.masmforum.com/board/index.php?PHPSESSID=786dd40408172108b65a5a36b09c88c0&topic=1286.0

jj2007

Quote from: Gunther on March 31, 2015, 09:55:44 PMa bit more understatement wouldn't be so bad.

Sense of humour is also a great asset :t