I get a memory access violation on these movs
Also, when I comment the mov's out and to an output of the argv.s my Int32 (CNTR:) is never what I expect. Can someone shed some light on this.

// AddId-
//
// This program will read each line in the
// file specified on the command line and
// append an auto incrementing ID to the end
// of each record. The id will start at the
// number passed in on the command line.

// Calling the program:
// AddId inFile startingID FieldSep outfile
// inFile: the name of the file to be read
// startingID: is the ID to assign to the first record
// fieldSep: the ID should first be prefixed by this character

// AddId myFile.dat 1000 ~ > myFile.id

program AddId;
#include( "stdlib.hhf" );

static

cntr: int32;
f1: file;
inFile: String;
fieldSep: String;
currentRec: String;

begin AddId;


// if( arg.c() <> 3 ) then
// stdout.put( "Usage: AddId inFile StartingID fieldSep > outFile" );
// exit AddId;
// endif;

mov( arg.v(1), inFile );
mov( arg.v(2), cntr );
mov( arg.v(3), fieldSep );
f1.open( inFile, fileio.r );
stdout.put( inFile, stdio.lf );
stdout.put( cntr, stdio.lf);
stdout.put( fieldSep, stdio.lf);

while( !f1.eof() ) do
f1.a_gets();
// mov( eax, currentRec );
// stdout.put( currentRec, fieldSep, cntr, stdio.lf );
// strfree( currentRec );
// inc(cntr);
endwhile;
//
f1.close();

end AddId;
Posted on 2003-06-02 13:47:03 by C. Wardell
I don't really know about HLA, but isn't arg.v(2) a string?
If so, you'll be mov-ing the first four bytes of the string to cntr

To check this, set the argument to "1111", if it comes out as:
hex 31313131h
decimal 825307441

Then it's just treating the first 4 bytes of the string as a number, not converting it to a number then assigning it.

If its something else, I can't help!

Mirno
Posted on 2003-06-02 17:18:11 by Mirno
I think your right.. The output of my last run was:

C:\radasm\Hla\Projects\AddID>addid cln.val 1000 *
cln.val
17050112
*

It seems like the 1000 on my command line is 17050112.

Would you happen to know how to cast the String into an Int.


Thanks.
Charlie
Posted on 2003-06-02 23:18:38 by C. Wardell

I get a memory access violation on these movs
Also, when I comment the mov's out and to an output of the argv.s my Int32 (CNTR:) is never what I expect. Can someone shed some light on this.



// AddId-
//
// This program will read each line in the
// file specified on the command line and
// append an auto incrementing ID to the end
// of each record. The id will start at the
// number passed in on the command line.

// Calling the program:
// AddId inFile startingID FieldSep outfile
// inFile: the name of the file to be read
// startingID: is the ID to assign to the first record
// fieldSep: the ID should first be prefixed by this character

// AddId myFile.dat 1000 ~ > myFile.id

program AddId;
#include( "stdlib.hhf" );

static

cntr: int32;
f1: file;
inFile: String;
fieldSep: String;
currentRec: String;

begin AddId;


// if( arg.c() <> 3 ) then
// stdout.put( "Usage: AddId inFile StartingID fieldSep > outFile" );
// exit AddId;
// endif;

mov( arg.v(1), inFile );
mov( arg.v(2), cntr );
mov( arg.v(3), fieldSep );
f1.open( inFile, fileio.r );
stdout.put( inFile, stdio.lf );
stdout.put( cntr, stdio.lf);
stdout.put( fieldSep, stdio.lf);

while( !f1.eof() ) do
f1.a_gets();
// mov( eax, currentRec );
// stdout.put( currentRec, fieldSep, cntr, stdio.lf );
// strfree( currentRec );
// inc(cntr);
endwhile;
//
f1.close();

end AddId;



Everything here is fine and dandy (for the most part) except for one crucial item - you're using a class object and you forgot to initialize that object before using it. In particular, f1's VMT (virtual method table) pointer contains garbage (probably NULL) and this is what is causing the fault.
Try inserting the following statement at the beginning of your code and see if this helps:

f1.create();

The string usage is correct. In HLA string objects are four-byte pointers and the mov instructions that copy the pointers returned by arg.v (in eax) are working just fine. The whole thing dies when you hit that f1.open statement (because the VMT ptr is not set up properly).

One last comment I'd make - you're specifying stdio.lf to emit a single line-feed at the end of each line. HLA provides a "nl" (newline) constant that is easier to user if you're really interested in emitting a new line (as opposed to explicitly emitting a line feed character), e.g.,

stdout.put( "Hello World" nl );

Cheers,
Randy Hyde
Posted on 2003-06-03 14:49:47 by rhyde
Thanks Randy,

I added the create line and it worked.
Posted on 2003-06-03 15:26:26 by C. Wardell