News:

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

Need example/tutorial on outputing to text file

Started by jimeeg, October 18, 2006, 07:32:28 PM

Previous topic - Next topic

jimeeg

Please be nice i am new to asm.

i have searched here and the all mighty google and i can't find a SIMPLE example or tutorial on how to output to a txt file or doc.  i know, i should know how to do this - i do in C, java, ada ... but for some reason i can't find an explanation i understand.
thx

P1

jimeeg,

Nothing fancy, just a basic output to error file routine.  You will need to create your own working variables for this snipet to work.

Regards,  P1  :8)

mov Timeout,100 ;Makes 20 seconds / 100 trys before aborting file write.
ReTryWrite:
invoke CreateFile,
       ADDR szEPathFileName,
       GENERIC_WRITE,
       0,
       NULL,
       OPEN_ALWAYS,
       FILE_ATTRIBUTE_NORMAL,
       NULL
.if eax == INVALID_HANDLE_VALUE
    invoke Sleep,200   ; .2 seconds for a retry.
    dec Timeout
    jz @F   ;OK, so just give up.
    jmp ReTryWrite
.else
    mov hErrorFile, eax
.endif

;invoke MessageBox,0,ADDR szErrorMessage,ADDR szMsgTitle,MB_OK
invoke SetFilePointer, hErrorFile, 0, NULL, FILE_END
invoke lstrlen, ADDR szErrorMessage
mov dwLength,eax
invoke WriteFile, hErrorFile, ADDR szErrorMessage, dwLength, ADDR dwErrorBW, NULL
invoke SetEndOfFile, hErrorFile
invoke CloseHandle, hErrorFile
@@:

jimeeg

okay, i "borrowed" some sample code and now have this:

  call GetTickCount   
    mov ecx, eax               
    add ecx, eax               
    mov edx, eax               
    add edx, ecx
    sub edx, eax 
    add eax, edx               
    print str$(eax)             
    print chr$(13,10,13,10)

    invoke CreateFile, ADDR Filename,GENERIC_WRITE,NULL,
                NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL

    mov hFile, eax
 
    invoke SetFilePointer,hFile,0,0,FILE_END
    invoke WriteFile, hFile,ADDR hFile,LENGTHOF hFile,ADDR pWritten,NULL
    invoke CloseHandle, hFile

How do i get eax to be the OUTPUT to the file as hex text or decimal?  all i get is zero's wearing hats  :dazzled:

what i would like to see is a nice neat column of the eax register value stored in my txt file.  any help would be appreciated ... until then i will search until my eyes bleed  :eek

Tedd

You need to convert the value in eax to a hex-string first, then write it to the file followed by a newline. Do this for each loop.
(DON'T createfile, setfilepointer, closehandle in every loop!!!!)
No snowflake in an avalanche feels responsible.

jimeeg

Quote from: Tedd on October 19, 2006, 03:59:25 PM
You need to convert the value in eax to a hex-string first, then write it to the file followed by a newline. Do this for each loop.
(DON'T createfile, setfilepointer, closehandle in every loop!!!!)


When i leave those out of the loop NOTHING prints. 

With the code as listed below all that does print out is the number 4???  is eax resetting for each loop?  Edit: i found my newline error.
.data?
     newline db " ",13,10," ",0

call GetTickCount
    mov ecx, eax               
    add ecx, eax               
    add ecx, eax               
    mov edx, eax               
    add edx, ecx
    add edx, ecx
    add edx, ecx
    shl edx, 4
    add edx, eax
    shl edx, 8
    sub edx, eax 
    add eax, edx               
    add eax, edx
    add eax, edx
    add eax, edx
    add eax, ebx
   
    print str$(eax)             
    print chr$(13,10,13,10)
     
    invoke dw2hex, eax, ADDR EaxString
    invoke CreateFile, ADDR Filename,GENERIC_WRITE,NULL,
                NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
    mov hFile, eax
    invoke SetFilePointer,hFile,0,0,FILE_END
    invoke WriteFile, hFile,ADDR EaxString,LENGTHOF EaxString,ADDR pWritten,NULL
    invoke WriteFile, hFile,ADDR newline,LENGTHOF newline,ADDR pWritten,NULL
    invoke CloseHandle, hFile

    sub cnt, 1
    jnz rng


What i found is that when i move the Print str command to just before the Sub Cnt,1 command my list prints all of the values like i want but then the screen output is all ONE's????  why is it that eax is not retaining the value?  is there a pop occuring that is causing this?  that is what it looks like to me ... what would you all suggest to keep the value for both places?  push it on the stack twice?

P1

Quote from: jimeeg on October 19, 2006, 05:30:52 PMWhen i leave those out of the loop NOTHING prints.
Leave the setup and close down code ( for the file handling ) outside the main loop.

You need to trace through your code because you don't understand what is doing what, to what yet.

You NEED this skill quickly.

Regards,  P1  :8)

jimeeg

Quote from: P1 on October 19, 2006, 06:09:33 PM
Quote from: jimeeg on October 19, 2006, 05:30:52 PMWhen i leave those out of the loop NOTHING prints.
Leave the setup and close down code ( for the file handling ) outside the main loop.

You need to trace through your code because you don't understand what is doing what, to what yet.

You NEED this skill quickly.

Regards,  P1  :8)

i have traced this through Olly and found that some external actions are taken on the registers after the calculations are completed, specifically a zeroing through the use of xor, but i can't figure out how to keep the value past that point for printing to the screen also.

PBrennick

Use the stack. If you cannot get it to work, post the 'complete' code and we can help you.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

P1

Quote from: jimeeg on October 20, 2006, 05:43:32 PMi have traced this through Olly and found that some external actions are taken on the registers after the calculations are completed, specifically a zeroing through the use of xor, but i can't figure out how to keep the value past that point for printing to the screen also.
You either preserve the register ( There are several methods available for this. ) or use a variable instead.

Just for the record, are you building skills or just trying to get homework done?

Regards,  P1  :8)

jimeeg

Building skills, trying to get some code to work, and finalizing some research.

i am working on the efficiency of a psuedo-random IP generator in an IPv6 environment.  while the thrust of this research is the coverage of the ip range, the way the ip generator develops ip's is not as important.

Thanks for all the help.

P1

Quote from: jimeeg on October 23, 2006, 02:38:12 PMi am working on the efficiency of a psuedo-random IP generator in an IPv6 environment.  while the thrust of this research is the coverage of the ip range, the way the ip generator develops ip's is not as important.
Ok, but ...   IPs are assigned, based on a authority.  Random geneartion seems to contradict the established practice/usage.  What is the point/purpose/goal/usage?

Regards,  P1  :8)

jimeeg

it's an IP scanning experiment.  right now i can't say more than that until my research is published.