Do i have to preserv registers for subclassed function ??
Posted on 2004-01-05 19:11:50 by AceEmbler
The short answer is YES. Have a look at this URL for a longer explanation why.

http://www.masmforum.com/viewtopic.php?t=117

Regards,
http://www.asmcommunity.net/board/cryptmail.php?tauntspiders=in.your.face@nomail.for.you&id=2f46ed9f24413347f14439b64bdc03fd
Posted on 2004-01-05 20:40:33 by hutch--
The somewhat longer answer, but somewhat shorter than hutches link:

You have to do register preservation of ebx,esi,edi,ebp (and the obvious esp) in callbacks, and have to assume that eax,ecx,edx are trashed on any call to outside code.
Posted on 2004-01-06 00:56:30 by f0dder
AceEmbler,

"You have to do register preservation of ebx,esi,edi,ebp..."

Should be:

You have to do register preservation of ebx,esi,edi,ebp,esp
IF you use&change them in callbacks AND if you use DispatchMessage API in
your message loop


Regards,
Lingo
Posted on 2004-01-06 14:38:47 by lingo12
Doesn't preserving mean making sure they're the same when you exit your callback? Nobody said you have to push/pop them if you aren't modifying them (and if they did, they're stupid).

There are other callbacks than just wndproc/dlgproc, and you better preserve the registers in any type.
Posted on 2004-01-06 14:44:07 by f0dder
If I have a procedural program, one that doesn't have any call backs, and that terminates with ExitProcess can I trash every register (even move esp from the stack segment to the top of my .data) before calling any windows API (i.e. CreateFile, MessageBox, etc.)? And do the API's preserve any registers that my app is using?
Posted on 2004-01-07 23:41:11 by eet_1024
Messing with ESP can be "dangerous" - iirc there's some values related to 'valid ESP range', and if ESP goes outside that range, your thread is terminated. You can adjust those values though, I think Maverick had a post about it. Also remember to keep ESP 4-byte aligned.

Otherwise, you should be able to trash whatever register you want - except probably the segment registers, and remember to clear the direction-flag before calling APIs. The APIs can trash eax,ecx,edx but must preserve ebx,esi,edi,ebp and will leave the directionflag clear.

I think that's about it?
Posted on 2004-01-08 03:19:25 by f0dder
fs:[4] is the upper stack limit and fs:[8] is the lower stack limit if I remember correctly.
Posted on 2004-01-08 05:57:12 by roticv