When I invoke nrandom, can I count on the values in EBX, ECX, EDX, ESI, EDI being the same after the call as they were before the call? I know that EAX contains the return value...
I ask because I remember reading that calls to Win32 functions can trash your registers.
The operative word here is "can". Yes, they can. And, yes, they do. Even the CRT_ routines. And, be aware, INVOKE of a CDECL function will automatically adjust the stack with:
add esp,n
instead of
lea esp,[esp+n]
thus destroying the flag registers.
I did a little test and it looks as if a call to nrandom will trash the value in EDX.
cork,
Nope, have a look at the help file ASMINTRO HELP and read the section on Register Preservation Convention. Once you have preserved EBX ESI and EDI in a normal stack frame procedure you can use them within the procedure BUT if you call another procedure it can alter EAX ECX + EDX.
Quote from: hutch-- on July 14, 2010, 12:10:35 AM
cork,
Nope, have a look at the help file ASMINTRO HELP and read the section on Register Preservation Convention. Once you have preserved EBX ESI and EDI in a normal stack frame procedure you can use them within the procedure BUT if you call another procedure it can alter EAX ECX + EDX.
Ah, okay. Thanks. I guess that makes good sense. Let the calling procedure preserve EAX, ECX or EDX if they need preserved. If the called procedure was required to preserve them, then it could being doing the work unnecessarily.