Hi all.....

This problem is regarding code mixing....

I have written a procedure in masm and successfully linked with a C file in VC.
However due some reason ( which I don't know ) the program crashes... when try to debug it through VC in-built dissembler...
I receive 1000volt charge because VC insert "leave" instruction before the "ret" in my procedure Which i have not used as result it causes a stack corruption..

How to remove this Leave instruction..............

Any idea ??? why is it so???
Posted on 2002-12-09 01:02:08 by processingspeed
Are you sure that you declared correctly your function? Maybe,this is the problem.
Posted on 2002-12-09 02:32:23 by Vortex
If you assembled it in MASM, it is masm that put it there. If its inline stuff then it could be VC.

leave is cleaning up the stack frame you created, so when you enter a proc there will usually be an entery which will push esp, mov ebp, esp (or similar). At the end of the proc this is undone by the leave (which masm helpfully does automatically for you every time you ret as they are intrinsicly linked).

If this is screwing you up (which you'll be able to tell because esp & ebp will not be the same after the ret as they were before the call), make sure you're popping the correct numbers of things off the stack inside the function call, and make sure that all C calling convention functions you call are correctly cleaning up after themselves.

Posted on 2002-12-09 03:41:08 by Mirno
Thanks alot guys but little bit of experimenting I get my job done...

However, the morale of this mess is that...

If you are using inline assembly or naked function in VC then you have to take care of the stack frame yourself .. i.e caller will clean up all the mess created for the callee function.
However if you r .. using procedure i.e proc... masm will take care of the mess created for the calling the function ..
Also, if you r using label for calling you function then no epilog and prolog will be generated by the masm for your function....

Once again thanks alot guys....
Posted on 2002-12-09 04:14:23 by processingspeed
Or you can do this:


some proc here
end some porc


Even if you dont use the stack frame in proc, MASM will still put a leave(EPILOGUE) in.
Posted on 2002-12-09 05:21:22 by ThoughtCriminal