News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

nrandom in the MASM32 library

Started by cork, July 13, 2010, 11:19:30 PM

Previous topic - Next topic

cork

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.

KeepingRealBusy

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.

cork

I did a little test and it looks as if a call to nrandom will trash the value in EDX.

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

cork

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.