News:

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

Preservation of ebx, edi, esi

Started by n00b!, December 13, 2008, 06:23:02 PM

Previous topic - Next topic

n00b!

QuoteThe three registers that must remain the same for each interaction with the operating system are,

EBX ESI EDI

Does this mean, that you have to preserve these if you're in a callback like a Window-Proc?
Otherways you can modify it freely like

.code
main:
  mov edi, 2
  xor ebx, ebx
  mov esi, eax
  invoke ExitProcess, 0
end main


If so, is there any other situation where you have to preserve them?

hutch--

noob,

many have advised this mistake, ANY INTERACTION with the operating system requires these registers to be preserved and this means not only a callback but ANY API CALL and the vast majority of library and external function calls written correctly.

If you protect these registers first you can create a subsystem that does not have to conform which is the case with some specialised code but when it is finished you must restore the system registers again.

This technique is used by the operating system to distribute the register preservation load between the OS and the user code so that both do the minimum register preservations for stable execution for each thread. Doing more than is needed slows that app down and increases the processor load, doing less than is needed delivers unreliable operation which varies from one OS version to the next and crashes that are very hard to debug.

Do it the right way the first time and you NEVER HAVE A PROBLEM with registers.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

GM

Hutch, StrToFloat doesn't preserve ebx edi esi.

hutch--

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php