News:

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

Access start parameters

Started by stom2008, August 05, 2008, 07:53:38 AM

Previous topic - Next topic

stom2008

Hello HLA-Forum,

I am new to HLA and so I do try to do my first steps (reading Randall Hydes great book).
And as I learnd you can only learn programming (hla) by programming I tried to write some very little programs.

Now I like to write an other little commandline hla program.

And here is my question:

Is it possible to access the commandline-start-parameter and how.




newhlaprg.exe -f /foo/bar/conf.conf -i test -d n


Now I like to "read" and use -f /foo/bar/conf.conf -i test -d n ... in the hla code.


many thanks for your help.

Best Regards,
Marcus




Sevag.K


program cmdprog;

#includeonce ("stdlib.hhf")

begin cmdprog;

arg.c();
mov( eax, ecx );
xor( ebx, ebx );
while( ebx < ecx ) do

arg.v( ebx );
stdout.put((type string eax ), nl );
inc( ebx );

endwhile;

end cmdprog;


stom2008

Cool,

Thank you very mutch.
Can you please explain the code a little bit for me. So that I can learn/understand how it works.

Best Regards,
Marcus


Sevag.K


Sure.

arg.c();

This command is in the hla standard library.  It initializes the command line using the underlying operating system and returns the number of arguments in EAX.

mov( eax, ecx );

This makes a copy of the value returned in EAX into ECX

xor( ebx, ebx );

This zeros out the EBX register.


The loop below cycles through all the arguments on the command line.
while( ebx < ecx ) do
   ...
   ...
endwhile;


arg.v( ebx );

This is another function in the standard library.  It returns a string parameter in EAX.  The current parameter number is indicated by EBX.

stdout.put((type string eax ), nl );

This standard library functions prints out the string value returned in EAX

inc( ebx );

Increases the argument counter.


stom2008

Hi Sevag,

Many thanks for the info.

Now I think I understand the code.

One last question:

Why do you make this copy?
mov( eax, ecx );

I think eax is a universal register so that it should be possible to use this register directly?

Best Regards,
Marcus




Sevag.K


EAX is not a good choice in this case since it is used as a return register.  For example, the arg.v function returns the string pointer in EAX.

Most of the standard library functions, even most Windows OS functions that return any value use EAX as a return register.




stom2008

...

Okay!

Tanks again.

Best Regards,
Marcus