News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Calling a MASM DLL procedure in a loop

Started by holgus103, February 07, 2016, 12:33:03 PM

Previous topic - Next topic

holgus103

Hi guys!

I'm pretty new to assembly, yet I think the best way to learn something new is by working on your own project. So that's exactly what I did, sadly I ran into a problem. I created a simple MASM Dll with MD5 procedures and now I've been trying to call them from my C++ application, but something really strange it happening. The iterator of the loop gets overwritten after returning from the called procedure.

Here is my main C++ code:
for (int i = 0; i < 64; i++){
    if (useAsm){
        if (0 <= i && i <= 15){//F
            F = FFunc(res[1],res[2],res[3]);
            g = i;
        }
        else if (16 <= i && i <= 31){//G
            F = GFunc(res[1], res[2], res[3]);
            g = ((5 * i + 1) & 0x0F);
        }
        else if (32 <= i & i <= 47){//H
            F = HFunc(res[1], res[2], res[3]);
            g = ((3 * i + 5) & 0x0F);
        }
        else if (48 <= i & i <= 63){//I
            F = IFunc(res[1], res[2], res[3]);
            g = ((7 * i) & 0x0F);
        }
    }
}
 
i gets overwritten when it is 24 exactly at
F = GFunc(res[1], res[2], res[3]);

I examined the assembly and it seems to be the fault of
add         esp,0Ch 

which is executed right after calling my procedure

Here is my procedure code:
;F := C xor (D and (B xor C))
GFunc proc Bval: DWORD,
Cval: DWORD,
Dval: DWORD
mov eax, Cval
xor eax, Bval
and eax, Dval
xor eax, Cval
ret
GFunc endp


FFunc is working just fine, am I doing something wrong? Do you guys have any idea why this is happening?

qWord

make sure to specify the same calling convention in C++ and for MASM, e.g.:
Gfnc PROC stdcall BVal:DWORD,... ==> extern "C" int __stdcall GFnc(...)

MREAL macros - when you need floating point arithmetic while assembling!

holgus103

Thanks, I didn't think of that. It worked :biggrin: