I was wondering how arguments are passed to programs, i know it can be done because whenever i use HLA i do it, ie HLA myprogram.hla, i always figured that myprogram.hla would mess up the exectution path of the main program, but obviously it doesn't, anybody can give me some examples on how this works
Thanks
Thanks
I'm not sure I understand you.
Do you want to write an HLA program that uses commandline arguments?
Do you want to write an HLA program that uses commandline arguments?
yea for example
Say if you had a program named caps.exe , and it capitilizes all characters in a string, and it gets the string from the command prompt as an argument, it's similar to when you assemble with HLA, you type C:/HLA myprogram.hla , "myprogram.hla" is the argument it accepts and the program uses that to know which one to assemble so
C:/caps.exe This is the string to capitilize
caps.exe would execute and load "This is the string to capitilize" into a string variable and do something like
I'm sure this is possible (Programmers note* I need type coercion on the "cmp(ecx,str.len(theString);" i believe, just trying to give an example
Say if you had a program named caps.exe , and it capitilizes all characters in a string, and it gets the string from the command prompt as an argument, it's similar to when you assemble with HLA, you type C:/HLA myprogram.hla , "myprogram.hla" is the argument it accepts and the program uses that to know which one to assemble so
C:/caps.exe This is the string to capitilize
caps.exe would execute and load "This is the string to capitilize" into a string variable and do something like
mov(theString,ebx);
mov(0,ecx);
Looper:
cmp(ecx, str.len(theString);
jae LoopedThruAll:
mov([ebx+ecx],al);
sub(32,al);
mov(al,s)
stdout.put(s);
inc(ecx);
jmp Looper;
LoopedThruAll:
I'm sure this is possible (Programmers note* I need type coercion on the "cmp(ecx,str.len(theString);" i believe, just trying to give an example
You can use the functions in the args module. The arg.c function accepts no parameters and returns in eax the number of commandline paramters passed to your program. You can then use the arg.v() function to extract indivdual commandline paramters. Here's an example:
program cmdline;
#include ("stdlib.hhf")
begin cmdline;
// Count commandline paramters
arg.c();
stdout.put( "Number of parameters = ", eax , nl );
mov( eax, edx );
for( mov( 0, ecx ); ecx < edx; inc ( ecx )) do
// Extract ecxth parameter
// Function returns a string
arg.v( ecx );
stdout.puts ( eax );
stdout.newln();
// Free String when we're
// done with it
strfree( eax );
endfor;
end cmdline;
Ooo thanks man, how bout this
Doesn't seem to work
program cmdline;
#include ("stdlib.hhf")
static
theString: string;
begin cmdline;
arg.cmdLn();
mov( eax, theString );
str.delete(theString,0,9);
fileio.openNew(theString);
end cmdline;
Doesn't seem to work
What doesn't work? Is the file not being created? I think using the arg.v function is the better way to get the individual command line parameters. I think you want to get the first commandline argument. You can do this easily using:
I think I didn't explain the example I posted earlier. :grin: Anyway it first counts the number of commandline parameters passed to the program and prints each of them.
arg.v( 1 );
mov( eax , theString );
...
strfree ( theString );
I think I didn't explain the example I posted earlier. :grin: Anyway it first counts the number of commandline parameters passed to the program and prints each of them.
Yea sorry bout that i was using my other code example to help a friend he wanted to load a parameter as a string into the program so i used that method.....
This seemed to like to work in C but HLA doesn't like it
How long have u been programming in HLA odyssey? you seem really good
Thanks
This seemed to like to work in C but HLA doesn't like it
program cmdline;
#include ("stdlib.hhf")
static
theString: string;
begin cmdline;
arg.v(1);
mov( eax, theString );
if(fileio.open(theString, fileio.rw)== NULL) then
fileio.openNew(theString);
endif;
end cmdline;
How long have u been programming in HLA odyssey? you seem really good
Thanks
The fileio.open function returns the handle to the file if it exists and raises an exception if it doesn't so to do what you want you'll have to handle the ex.FileOpenFailure exception. Here an example:
I started really learning asm about a year ago around the same time I joined this forum and I began to read aoa32 and I learned a bit about HLA in the process :grin: . I'm still not finished reading it yet. It's a huge book and I'm at volume 3 :grin: If I didn't hang around these forums so much I would get more time to read it :grin:
program cmdline;
#include ("stdlib.hhf")
static
theString: string;
begin cmdline;
arg.v(1);
mov( eax, theString );
try
fileio.open( theString, fileio.rw );
exception ( ex.FileOpenFailure );
fileio.openNew ( theString );
endtry;
fileio.close ( eax );
end cmdline;
I started really learning asm about a year ago around the same time I joined this forum and I began to read aoa32 and I learned a bit about HLA in the process :grin: . I'm still not finished reading it yet. It's a huge book and I'm at volume 3 :grin: If I didn't hang around these forums so much I would get more time to read it :grin: