=========================== C-code
{
DWORD Len ;
char szBuffer[256] ;
memset(szBuffer, 'A', sizeof(szBuffer)) ;
SetFilePointer(hFile,0,NULL,FILE_BEGIN) ;
while (hFileSize > 0) {
Len = (hFileSize > sizeof(szBuffer)) ? sizeof(szBuffer) : hFileSize ;
WriteFile(hFile, szBuffer, Len, &Len, NULL) ;
hFileSize -= Len ;
}
FlushFileBuffers(hFile) ;
}
=========================== MASM code attempt
invoke SetFilePointer, , 0, NULL, FILE_BEGIN
.while (hFileSize > 0)
.if hFileSize > SIZEOF szBuffer
mov Len, SIZEOF szBuffer
.else
mov Len, hFileSize <!--- compiler doesn't like this...
.endif
invoke WriteFile, , ADDR szBuffer, Len, ADDR nBytesWritten, NULL
sub hFileSize, Len <!--- compiler doesn't like this...
.endw
invoke FlushFileBuffers,
^I'm trying to convert the following c-code to assembly. below is my attempt but
i know my while loop is wrong. it wont compile right.
i have all the following variables i need (szBuffer, hFileSize, Len, nBytesWritten etc...)
but i just cant figure out how to end this while loop correctly.
does anyone have any idea how to correctly translate the code from C to MASM?
{
DWORD Len ;
char szBuffer[256] ;
memset(szBuffer, 'A', sizeof(szBuffer)) ;
SetFilePointer(hFile,0,NULL,FILE_BEGIN) ;
while (hFileSize > 0) {
Len = (hFileSize > sizeof(szBuffer)) ? sizeof(szBuffer) : hFileSize ;
WriteFile(hFile, szBuffer, Len, &Len, NULL) ;
hFileSize -= Len ;
}
FlushFileBuffers(hFile) ;
}
=========================== MASM code attempt
invoke SetFilePointer, , 0, NULL, FILE_BEGIN
.while (hFileSize > 0)
.if hFileSize > SIZEOF szBuffer
mov Len, SIZEOF szBuffer
.else
mov Len, hFileSize <!--- compiler doesn't like this...
.endif
invoke WriteFile, , ADDR szBuffer, Len, ADDR nBytesWritten, NULL
sub hFileSize, Len <!--- compiler doesn't like this...
.endw
invoke FlushFileBuffers,
^I'm trying to convert the following c-code to assembly. below is my attempt but
i know my while loop is wrong. it wont compile right.
i have all the following variables i need (szBuffer, hFileSize, Len, nBytesWritten etc...)
but i just cant figure out how to end this while loop correctly.
does anyone have any idea how to correctly translate the code from C to MASM?
mov Len, hFileSize <!--- compiler doesn't like this...
sub hFileSize, Len <!--- compiler doesn't like this.
Because you can't do memory to memory operations. You have to either use registers or push/pop to transfer variables from one to another.
A macro I like and use for such purposes is $eax defined as:
$eax macro arg
mov eax, arg
exitm <eax>
endm
Using that macro you could write:
mov Len, $eax(hFileSize)
sub hFileSize, $eax(Len)
Cheers :)
Mr. JimmyClif, you just saved me a bunch of headache. Thanks for helping me out!